mirror of
https://github.com/github/semantic.git
synced 2024-12-26 08:25:19 +03:00
Terms are Cofrees.
This commit is contained in:
parent
9782ce1f62
commit
865b38bc2e
34
Diff.hs
34
Diff.hs
@ -13,32 +13,32 @@ data Range = Range { start :: Int, end :: Int }
|
||||
|
||||
data Info = Info -- Range [String]
|
||||
|
||||
type Term a = Fix (Syntax a)
|
||||
type Term a annotation = Cofree (Syntax a) annotation
|
||||
data Patch a = Patch { old :: Maybe a, new :: Maybe a }
|
||||
type Diff a = Free (Syntax a) (Patch (Term a))
|
||||
type Diff a = Free (Syntax a) (Patch (Term a Info))
|
||||
|
||||
(</>) :: Maybe (Term a) -> Maybe (Term a) -> Diff a
|
||||
(</>) :: Maybe (Term a Info) -> Maybe (Term a Info) -> Diff a
|
||||
(</>) a b = Pure $ Patch { old = a, new = b }
|
||||
|
||||
a :: Term String
|
||||
a = Fix $ Keyed $ fromList [
|
||||
("hello", Fix $ Indexed [ Fix $ Leaf "hi" ]),
|
||||
("goodbye", Fix $ Leaf "goodbye") ]
|
||||
a :: Term String Info
|
||||
a = Cofree Info $ Keyed $ fromList [
|
||||
("hello", Cofree Info $ Indexed [ Fix $ Leaf "hi" ]),
|
||||
("goodbye", Cofree Info $ Leaf "goodbye") ]
|
||||
|
||||
b :: Term String
|
||||
b = Fix $ Keyed $ fromList [
|
||||
("hello", Fix $ Indexed []),
|
||||
("goodbye", Fix $ Indexed []) ]
|
||||
b :: Term String Info
|
||||
b = Cofree Info $ Keyed $ fromList [
|
||||
("hello", Cofree Info $ Indexed []),
|
||||
("goodbye", Cofree Info $ Indexed []) ]
|
||||
|
||||
d :: Diff String
|
||||
d = Free $ Keyed $ fromList [
|
||||
("hello", Free $ Indexed [ Just (Fix $ Leaf "hi") </> Nothing ]),
|
||||
("goodbye", Just (Fix $ Leaf "goodbye") </> Just (Fix $ Indexed [])) ]
|
||||
("hello", Free $ Indexed [ Just (Cofree Info $ Leaf "hi") </> Nothing ]),
|
||||
("goodbye", Just (Cofree Info $ Leaf "goodbye") </> Just (Cofree Info $ Indexed [])) ]
|
||||
|
||||
data Operation a f
|
||||
= Recur (Term a) (Term a) (Diff a -> f)
|
||||
| ByKey [(String, Term a)] [(String, Term a)] ([(String, Diff a)] -> f)
|
||||
| ByIndex [Term a] [Term a] ([Diff a] -> f)
|
||||
= Recur (Term a Info) (Term a Info) (Diff a -> f)
|
||||
| ByKey [(String, Term a Info)] [(String, Term a Info)] ([(String, Diff a)] -> f)
|
||||
| ByIndex [Term a Info] [Term a Info] ([Diff a] -> f)
|
||||
|
||||
type Algorithm a = Free (Operation a)
|
||||
|
||||
@ -58,4 +58,4 @@ type RangedTerm a = Cofree (Syntax a) Int
|
||||
-- data Difff a f = Difff (Either (Patch (Term a)) (Syntax a f))
|
||||
-- type RangedDiff a = Cofree (Difff a) Range
|
||||
data AnnotatedSyntax a f = AnnotatedSyntax (Range, Syntax a f)
|
||||
type RangedDiff a = Free (AnnotatedSyntax a) (Patch (Term a))
|
||||
type RangedDiff a = Free (AnnotatedSyntax a) (Patch (Term a Info))
|
||||
|
Loading…
Reference in New Issue
Block a user