1
1
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:
Rob Rix 2019-06-25 17:39:15 -04:00
parent 1e3b473fc7
commit 9db69d80fa
No known key found for this signature in database
GPG Key ID: F188A01508EA1CF7
2 changed files with 14 additions and 1 deletions

View File

@ -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)

View File

@ -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 }