1 Nov 2012 02:51
Looking for advice on modelling a 3-way merge (with varying strategies)
Oliver Charles <oliver.g.charles <at> gmail.com>
2012-11-01 01:51:26 GMT
2012-11-01 01:51:26 GMT
Hello,
I'm currently trying to implement a way 3 way merge, that is dispatched
on type. Essentially, I want to be able to say "I have this large data
type which is a product of various other types - here's how to merge
it".
By 3 way merge, I mean that I have a 'new' value, a 'current' value and
a 'common ancestor' value. So far I have:
import Control.Applicative
import Data.Monoid
newtype Merge a = Merge { runMerge :: Either [String] a }
instance Functor Merge where
fmap f a = Merge $ fmap f $ runMerge a
instance Applicative Merge where
pure = Merge . Right
(Merge (Right f)) <*> (Merge (Right a)) = Merge $ Right $ f a
(Merge (Right _)) <*> (Merge (Left c)) = Merge $ Left $ c
(Merge (Left c)) <*> (Merge (Left c')) = Merge $ Left $ c <> c'
(Merge (Left c)) <*> _ = Merge $ Left $ c
ok :: a -> Merge a
ok = pure
failMerge :: String -> Merge a
failMerge x = Merge $ Left [x]
(Continue reading)
RSS Feed