From 04a3d5200729a512856d3060dd6609b208a37b4d Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Thu, 4 Aug 2016 12:13:48 -0400 Subject: [PATCH] :memo: diffTerms. --- src/Interpreter.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Interpreter.hs b/src/Interpreter.hs index d4264797c..d8f1ddd18 100644 --- a/src/Interpreter.hs +++ b/src/Interpreter.hs @@ -24,8 +24,14 @@ type Comparable leaf annotation = Term leaf annotation -> Term leaf annotation - -- | Constructs a diff from the CofreeF containing its annotation and syntax. This function has the opportunity to, for example, cache properties in the annotation. type DiffConstructor leaf annotation = CofreeF (Syntax leaf) (Both annotation) (Diff leaf annotation) -> Diff leaf 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) +-- | Diff two terms recursively, given functions characterizing the diffing. +diffTerms :: (Eq leaf, Hashable leaf, Eq (Record fields), HasField fields Category) => + DiffConstructor leaf (Record fields) -> -- ^ A function to wrap up & possibly annotate every produced diff. + Comparable leaf (Record fields) -> -- ^ A function to determine whether or not two terms should even be compared. + SES.Cost (Diff leaf (Record fields)) -> -- ^ A function to compute the cost of a given diff node. + Term leaf (Record fields) -> -- ^ A term representing the old state. + Term leaf (Record fields) -> -- ^ A term representing the new state. + Diff leaf (Record fields) diffTerms construct comparable cost a b = fromMaybe (replacing a b) $ diffComparableTerms construct comparable cost a b 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))