2015-11-18 00:25:36 +03:00
|
|
|
module Diff where
|
|
|
|
|
2015-11-18 00:35:55 +03:00
|
|
|
import Syntax
|
2015-11-18 00:25:36 +03:00
|
|
|
import Data.Maybe
|
2015-11-18 00:44:27 +03:00
|
|
|
import Data.Map
|
2015-11-18 00:35:52 +03:00
|
|
|
import Control.Monad.Free
|
2015-11-18 01:07:36 +03:00
|
|
|
import Control.Comonad.Cofree
|
2015-11-18 05:23:53 +03:00
|
|
|
import Patch
|
2015-11-18 22:28:16 +03:00
|
|
|
import Term
|
2015-11-18 00:25:36 +03:00
|
|
|
|
|
|
|
data Range = Range { start :: Int, end :: Int }
|
|
|
|
|
2015-11-18 01:17:20 +03:00
|
|
|
data Info = Info -- Range [String]
|
2015-11-18 22:19:16 +03:00
|
|
|
deriving Eq
|
2015-11-18 00:25:36 +03:00
|
|
|
|
2015-11-18 01:17:55 +03:00
|
|
|
type Diff a = Free (Syntax a) (Patch (Term a Info))
|
2015-11-18 00:25:36 +03:00
|
|
|
|
|
|
|
cost :: Diff a -> Integer
|
|
|
|
cost f = iter c $ fmap g f where
|
2015-11-18 03:17:42 +03:00
|
|
|
c (Leaf _) = 0
|
|
|
|
c (Keyed xs) = sum $ snd <$> toList xs
|
|
|
|
c (Indexed xs) = sum xs
|
|
|
|
c (Fixed xs) = sum xs
|
|
|
|
g _ = 1
|