From 9f6fb541a75aee9876e1db238069656ccc572287 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 3 Aug 2016 18:58:37 -0400 Subject: [PATCH] Define run by iteration. --- src/Interpreter.hs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 546ea1f4b..c6e2d683f 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -44,9 +44,8 @@ constructAndRun construct comparable cost t1 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)) -run construct comparable cost algorithm = case runFree algorithm of - Pure diff -> Just diff - Free (Recursive t1 t2 f) -> run construct comparable cost . f $ recur a b where +run construct comparable cost algorithm = (`iter` fmap Just algorithm) $ \case + Recursive t1 t2 f -> f $ recur a b where (annotation1 :< a, annotation2 :< b) = (runCofree t1, runCofree t2) annotate = construct . (both annotation1 annotation2 :<) @@ -54,9 +53,9 @@ run construct comparable cost algorithm = case runFree algorithm of diffThese = these (pure . Delete) (pure . Insert) (diffTerms construct comparable cost) - Free (ByIndex a b f) -> run construct comparable cost . f $ ses (constructAndRun construct comparable cost) cost a b + ByIndex a b f -> f $ ses (constructAndRun construct comparable cost) cost a b - Free (ByRandomWalkSimilarity a b f) -> run construct comparable cost . f $ rws (constructAndRun construct comparable cost) getLabel a b + ByRandomWalkSimilarity a b f -> f $ rws (constructAndRun construct comparable cost) getLabel a b where getLabel (h :< t) = (category h, case t of Leaf s -> Just s _ -> Nothing)