2015-11-18 00:25:36 +03:00
|
|
|
|
module Diff where
|
|
|
|
|
|
2016-05-03 21:10:25 +03:00
|
|
|
|
import Control.Comonad.Trans.Cofree
|
2016-03-01 05:48:58 +03:00
|
|
|
|
import Control.Monad.Free
|
2016-02-29 18:12:34 +03:00
|
|
|
|
import Data.Functor.Both
|
2015-11-18 05:23:53 +03:00
|
|
|
|
import Patch
|
2016-02-29 18:04:59 +03:00
|
|
|
|
import Syntax
|
|
|
|
|
import Term
|
2015-11-18 00:25:36 +03:00
|
|
|
|
|
2016-01-14 21:50:19 +03:00
|
|
|
|
-- | An annotated syntax in a diff tree.
|
2016-05-03 21:10:25 +03:00
|
|
|
|
type Annotated a annotation f = CofreeF (Syntax a) annotation f
|
|
|
|
|
|
|
|
|
|
annotation :: Annotated a annotation f -> annotation
|
|
|
|
|
annotation = headF
|
|
|
|
|
|
|
|
|
|
syntax :: Annotated a annotation f -> Syntax a f
|
|
|
|
|
syntax = tailF
|
2015-11-19 03:13:33 +03:00
|
|
|
|
|
2016-05-03 21:19:10 +03:00
|
|
|
|
annotate :: annotation -> Syntax a f -> CofreeF (Syntax a) annotation f
|
|
|
|
|
annotate = (:<)
|
|
|
|
|
|
2016-01-14 20:30:21 +03:00
|
|
|
|
-- | An annotated series of patches of terms.
|
2016-05-03 21:10:25 +03:00
|
|
|
|
type Diff a annotation = Free (CofreeF (Syntax a) (Both annotation)) (Patch (Term a annotation))
|
2015-11-18 00:25:36 +03:00
|
|
|
|
|
2016-01-14 20:30:21 +03:00
|
|
|
|
-- | Sum the result of a transform applied to all the patches in the diff.
|
2015-12-01 03:06:48 +03:00
|
|
|
|
diffSum :: (Patch (Term a annotation) -> Integer) -> Diff a annotation -> Integer
|
2015-12-01 18:13:05 +03:00
|
|
|
|
diffSum patchCost diff = sum $ fmap patchCost diff
|
2015-12-01 03:06:48 +03:00
|
|
|
|
|
2016-04-11 22:06:59 +03:00
|
|
|
|
-- | The sum of the node count of the diff’s patches.
|
2015-11-27 20:06:14 +03:00
|
|
|
|
diffCost :: Diff a annotation -> Integer
|
2015-12-01 03:16:22 +03:00
|
|
|
|
diffCost = diffSum $ patchSum termSize
|