From 47c2bdc60e7a2b92da7c221185e3dec59ee9cc70 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 4 Aug 2016 11:00:29 -0400 Subject: [PATCH] Use the diff constructor within algorithmWithTerms to compute costs &c. --- src/Interpreter.hs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 344347af9..de297ec3e 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -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))