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:44:27 +03:00
|
|
|
import Data.Map
|
2015-11-19 23:02:53 +03:00
|
|
|
import Data.Set
|
2015-11-18 00:35:52 +03:00
|
|
|
import Control.Monad.Free
|
2015-11-18 05:23:53 +03:00
|
|
|
import Patch
|
2015-11-18 22:28:16 +03:00
|
|
|
import Term
|
2015-11-19 23:06:34 +03:00
|
|
|
import Categorizable
|
2015-11-18 00:25:36 +03:00
|
|
|
|
2015-11-19 03:13:33 +03:00
|
|
|
data Annotated a annotation f = Annotated annotation (Syntax a f)
|
|
|
|
deriving (Functor, Eq, Show)
|
|
|
|
|
2015-11-20 02:05:29 +03:00
|
|
|
data Range = Range { start :: Int, end :: Int }
|
2015-11-19 23:02:53 +03:00
|
|
|
deriving (Eq, Show)
|
2015-11-18 00:25:36 +03:00
|
|
|
|
2015-11-20 01:35:46 +03:00
|
|
|
type Category = String
|
2015-11-20 01:36:07 +03:00
|
|
|
data Info = Info Range (Set Category)
|
2015-11-19 23:04:18 +03:00
|
|
|
deriving (Eq, Show)
|
2015-11-18 00:25:36 +03:00
|
|
|
|
2015-11-19 23:06:34 +03:00
|
|
|
instance Categorizable Info where
|
|
|
|
categories (Info _ c) = c
|
|
|
|
|
2015-11-19 22:27:31 +03:00
|
|
|
type Diff a annotation = Free (Annotated a (annotation, annotation)) (Patch (Term a annotation))
|
2015-11-18 00:25:36 +03:00
|
|
|
|
2015-12-01 03:06:48 +03:00
|
|
|
diffSum :: (Patch (Term a annotation) -> Integer) -> Diff a annotation -> Integer
|
|
|
|
diffSum patchCost diff = iter (c . unwrap) $ fmap patchCost diff where
|
|
|
|
c (Leaf _) = 0
|
|
|
|
c (Keyed xs) = sum $ snd <$> Data.Map.toList xs
|
|
|
|
c (Indexed xs) = sum xs
|
|
|
|
c (Fixed xs) = sum xs
|
|
|
|
unwrap (Annotated _ syntax) = syntax
|
|
|
|
|
2015-11-27 20:06:14 +03:00
|
|
|
diffCost :: Diff a annotation -> Integer
|
|
|
|
diffCost f = iter (c . unwrap) $ fmap (const 1) f where
|
2015-11-19 23:20:57 +03:00
|
|
|
c (Leaf _) = 0
|
|
|
|
c (Keyed xs) = sum $ snd <$> Data.Map.toList xs
|
|
|
|
c (Indexed xs) = sum xs
|
|
|
|
c (Fixed xs) = sum xs
|
|
|
|
unwrap (Annotated _ syntax) = syntax
|