diff --git a/src/Interpreter.hs b/src/Interpreter.hs index 77872b8fa..9080f56ea 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -27,7 +27,9 @@ type DiffConstructor leaf annotation = CofreeF (Syntax leaf) (Both annotation) ( -- | Diff two terms, given a function that determines whether two terms can be compared and a cost function. diffTerms :: (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) -> Diff leaf (Record fields) -diffTerms construct comparable cost a b = fromMaybe (replacing a b) $ constructAndRun construct comparable cost a b +diffTerms construct comparable cost a b + | not (comparable a b) = replacing a b + | otherwise = fromMaybe (replacing a b) $ run construct comparable cost (algorithmWithTerms a b) -- | Constructs an algorithm and runs it constructAndRun :: (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))