mirror of
https://github.com/github/semantic.git
synced 2024-12-24 23:42:31 +03:00
Add a merge function to compute a Term from a Diff.
This commit is contained in:
parent
3f6cab2abc
commit
9829d2df84
@ -24,6 +24,12 @@ diffSum patchCost diff = sum $ fmap patchCost diff
|
||||
diffCost :: Diff a annotation -> Integer
|
||||
diffCost = diffSum $ patchSum termSize
|
||||
|
||||
merge :: (Patch (Term leaf annotation) -> Term leaf annotation) -> Diff leaf annotation -> Term leaf annotation
|
||||
merge transform = cata algebra . fmap transform
|
||||
where algebra :: FreeF (CofreeF (Syntax leaf) (Both annotation)) (Term leaf annotation) (Term leaf annotation) -> Term leaf annotation
|
||||
algebra (Pure p) = p
|
||||
algebra (Free (annotations :< syntax)) = cofree (Both.fst annotations :< syntax)
|
||||
|
||||
beforeTerm :: Diff leaf annotation -> Maybe (Term leaf annotation)
|
||||
beforeTerm = cata algebra
|
||||
where algebra :: FreeF (CofreeF (Syntax leaf) (Both annotation)) (Patch (Term leaf annotation)) (Maybe (Term leaf annotation)) -> Maybe (Term leaf annotation)
|
||||
|
Loading…
Reference in New Issue
Block a user