mirror of
https://github.com/github/semantic.git
synced 2024-11-28 10:15:55 +03:00
Add some helpers for Incr.
This commit is contained in:
parent
1e3b473fc7
commit
9db69d80fa
@ -29,7 +29,7 @@ import qualified Data.IntSet as IntSet
|
||||
import Data.List.NonEmpty (nonEmpty)
|
||||
import Data.Loc
|
||||
import qualified Data.Map as Map
|
||||
import Data.Name
|
||||
import Data.Name hiding (subst)
|
||||
import qualified Data.Set as Set
|
||||
import Prelude hiding (fail)
|
||||
|
||||
|
@ -14,6 +14,9 @@ module Data.Name
|
||||
, runNaming
|
||||
, NamingC(..)
|
||||
, Incr(..)
|
||||
, match
|
||||
, subst
|
||||
, incr
|
||||
) where
|
||||
|
||||
import Control.Applicative
|
||||
@ -130,3 +133,13 @@ data Incr a
|
||||
= Z
|
||||
| S a
|
||||
deriving (Eq, Foldable, Functor, Ord, Show, Traversable)
|
||||
|
||||
match :: Eq a => a -> a -> Incr a
|
||||
match x y | x == y = Z
|
||||
| otherwise = S y
|
||||
|
||||
subst :: a -> Incr a -> a
|
||||
subst a = incr a id
|
||||
|
||||
incr :: b -> (a -> b) -> Incr a -> b
|
||||
incr z s = \case { Z -> z ; S a -> s a }
|
||||
|
Loading…
Reference in New Issue
Block a user