1
1
mirror of https://github.com/github/semantic.git synced 2024-12-22 14:21:31 +03:00

Use the diff constructor within algorithmWithTerms to compute costs &c.

This commit is contained in:
Rob Rix 2016-08-04 11:00:29 -04:00
parent 58fe4fdc89
commit 47c2bdc60e

View File

@ -32,7 +32,7 @@ diffTerms construct comparable cost a b = fromMaybe (replacing a b) $ diffCompar
diffComparableTerms :: (Eq leaf, Hashable leaf, Eq (Record fields), HasField fields Category) => DiffConstructor leaf (Record fields) -> Comparable leaf (Record fields) -> SES.Cost (Diff leaf (Record fields)) -> Term leaf (Record fields) -> Term leaf (Record fields) -> Maybe (Diff leaf (Record fields))
diffComparableTerms construct comparable cost a b
| (category <$> a) == (category <$> b) = hylo construct runCofree <$> zipTerms a b
| comparable a b = run construct comparable cost (algorithmWithTerms a b)
| comparable a b = run construct comparable cost (algorithmWithTerms construct a b)
| otherwise = Nothing
-- | Constructs an algorithm and runs it
@ -49,14 +49,14 @@ constructAndRun construct comparable cost t1 t2
_ -> recursively t1 t2
annotate = pure . construct . (both (extract t1) (extract t2) :<)
algorithmWithTerms :: Eq leaf => Term leaf (Record fields) -> Term leaf (Record fields) -> Algorithm (Term leaf (Record fields)) (Diff leaf (Record fields)) (Diff leaf (Record fields))
algorithmWithTerms t1 t2 = case (unwrap t1, unwrap t2) of
algorithmWithTerms :: Eq leaf => DiffConstructor leaf (Record fields) -> Term leaf (Record fields) -> Term leaf (Record fields) -> Algorithm (Term leaf (Record fields)) (Diff leaf (Record fields)) (Diff leaf (Record fields))
algorithmWithTerms construct t1 t2 = case (unwrap t1, unwrap t2) of
(Indexed a, Indexed b) -> do
diffs <- byIndex a b
annotate (Indexed diffs)
(Leaf a, Leaf b) | a == b -> annotate (Leaf b)
_ -> recursively t1 t2
where annotate = pure . wrap . (both (extract t1) (extract t2) :<)
where annotate = pure . construct . (both (extract t1) (extract t2) :<)
-- | Runs the diff algorithm
run :: (Eq leaf, Hashable leaf, Eq (Record fields), HasField fields Category) => DiffConstructor leaf (Record fields) -> Comparable leaf (Record fields) -> SES.Cost (Diff leaf (Record fields)) -> Algorithm (Term leaf (Record fields)) (Diff leaf (Record fields)) (Diff leaf (Record fields)) -> Maybe (Diff leaf (Record fields))