1
1
mirror of https://github.com/github/semantic.git synced 2025-01-03 04:51:57 +03:00

Define a smart constructor for let-binding diffs.

This commit is contained in:
Rob Rix 2017-09-10 19:56:06 +01:00
parent d68a8790ce
commit 289cb11912

View File

@ -61,6 +61,11 @@ maxBoundMetavariable = cata $ \ diff -> case diff of
foldMaxMap :: (Foldable t, Ord b) => (a -> Maybe b) -> t a -> Maybe b
foldMaxMap f = foldr (max . f) Nothing
letDiff :: (Foldable syntax, Functor syntax) => Diff syntax ann -> (Metavar -> TermF syntax (Both ann) (Diff syntax ann)) -> Diff syntax ann
letDiff diff f = Diff (Copy [(n, diff)] body)
where body = f n
n = maybe (Metavar 0) succ (foldMaxMap maxBoundMetavariable (termSyntax body))
newtype Env a = Env { unEnv :: [(Metavar, a)] }
deriving (Eq, Foldable, Functor, Monoid, Ord, Show, Traversable)