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:
parent
d68a8790ce
commit
289cb11912
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user