From 37b59c89d7e197531718734dcfdf504d7daad47c Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Fri, 17 Jun 2016 13:28:35 -0400 Subject: [PATCH] Use the setter functions to update Info. --- src/Alignment.hs | 2 +- src/Diffing.hs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Alignment.hs b/src/Alignment.hs index 3533c715a..49fefc24a 100644 --- a/src/Alignment.hs +++ b/src/Alignment.hs @@ -69,7 +69,7 @@ alignSyntax toJoinThese toNode getRange sources (infos :< syntax) = case syntax Keyed children -> catMaybes $ wrapInBranch (Keyed . Map.fromList) <$> alignBranch (getRange . Prologue.snd) (Map.toList children >>= pairWithKey) bothRanges where bothRanges = modifyJoin (fromThese [] []) lineRanges lineRanges = toJoinThese $ actualLineRanges <$> (characterRange <$> infos) <*> sources - wrapInBranch constructor = applyThese $ toJoinThese ((\ info (range, children) -> toNode (info { characterRange = range } :< constructor children)) <$> infos) + wrapInBranch constructor = applyThese $ toJoinThese ((\ info (range, children) -> toNode (setCharacterRange info range :< constructor children)) <$> infos) pairWithKey (key, values) = fmap ((,) key) <$> values -- | Given a function to get the range, a list of already-aligned children, and the lists of ranges spanned by a branch, return the aligned lines. diff --git a/src/Diffing.hs b/src/Diffing.hs index c3d2b1a96..2e163f0bb 100644 --- a/src/Diffing.hs +++ b/src/Diffing.hs @@ -55,13 +55,13 @@ breakDownLeavesByWord :: Source Char -> Term T.Text Info -> Term T.Text Info breakDownLeavesByWord source = cata replaceIn where replaceIn :: TermF T.Text Info (Term T.Text Info) -> Term T.Text Info - replaceIn (info :< syntax) = let size' = 1 + sum (size . extract <$> syntax') in cofree $ info { size = size', cost = size' } :< syntax' + replaceIn (info :< syntax) = let size' = 1 + sum (size . extract <$> syntax') in cofree $ setCost (setSize info size') size' :< syntax' where syntax' = case (ranges, syntax) of (_:_:_, Leaf _) -> Indexed (makeLeaf info <$> ranges) _ -> syntax ranges = rangesAndWordsInSource (characterRange info) rangesAndWordsInSource range = rangesAndWordsFrom (start range) (toString $ slice range source) - makeLeaf info (range, substring) = cofree $ info { characterRange = range } :< Leaf (T.pack substring) + makeLeaf info (range, substring) = cofree $ setCharacterRange info range :< Leaf (T.pack substring) -- | Transcode a file to a unicode source. transcode :: B1.ByteString -> IO (Source Char) @@ -95,7 +95,7 @@ diffFiles parser renderer sourceBlobs = do pure $! renderer textDiff sourceBlobs where construct :: CofreeF (Syntax Text) (Both Info) (Diff Text Info) -> Diff Text Info construct (info :< syntax) = free (Free ((setCost <$> info <*> sumCost syntax) :< syntax)) - setCost info cost = info { cost = cost } + setCost info cost = setCost info cost sumCost = fmap getSum . foldMap (fmap Sum . getCost) getCost diff = case runFree diff of Free (info :< _) -> cost <$> info