From 1b02940e26015aece8c2f0b41b0ba3018ddc9257 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 2 Aug 2016 13:56:48 -0400 Subject: [PATCH] Combine the gram at each node in. --- src/Diffing.hs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Diffing.hs b/src/Diffing.hs index 2fa284235..56a726870 100644 --- a/src/Diffing.hs +++ b/src/Diffing.hs @@ -129,9 +129,12 @@ termCostDecorator :: (Prologue.Foldable f, Functor f) => TermDecorator f a Cost termCostDecorator c = 1 + sum (cost <$> tailF c) pqGramDecorator :: (Prologue.Foldable f, Functor f) => (forall b. CofreeF f (Record a) b -> label) -> Int -> Int -> TermDecorator f a (Gram label, DList.DList (Gram label)) -pqGramDecorator getLabel p q c@(a :< s) = (Gram [] [ Just (getLabel c) ], foldMap (Prologue.snd . childGrams) s) - where childGrams :: HasField fields (Gram label, DList.DList (Gram label)) => Record fields -> (Gram label, DList.DList (Gram label)) - childGrams = getField +pqGramDecorator getLabel p q c@(a :< s) = (Gram [] [ Just label ], foldMap (childGrams label) s) + where childGrams :: HasField fields (Gram label, DList.DList (Gram label)) => label -> Record fields -> DList.DList (Gram label) + childGrams label record = let (child, grandchildren) = getField record in + DList.singleton (prependParent label child) <> grandchildren + prependParent label gram = gram { stem = Just label : stem gram } + label = getLabel c -- | The sum of the node count of the diff’s patches. diffCostWithCachedTermCosts :: HasField fields Cost => Diff leaf (Record fields) -> Integer