Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module Data.Diff (Diff, Diffable, diff, patch) where
- import Data.Flat.Instances ()
- import GHC.Generics (Generic)
- import Linear (V2(V2))
- class Eq a => Diffable a where
- data Diff a
- diff :: a -> a -> Maybe (Diff a)
- patch :: a -> Diff a -> a
- instance Diffable a => Diffable (V2 a) where
- newtype Diff (V2 a) = DiffV2 (V2 (Maybe (Diff a)))
- deriving (Generic)
- diff v@(V2 x y) v'@(V2 x' y')
- | v == v' = Nothing
- | otherwise = Just . DiffV2 $ V2 (diff x x') (diff y y')
- patch (V2 x y) (DiffV2 (V2 xd yd)) = V2
- ((maybe <*> patch) x xd)
- ((maybe <*> patch) y yd)
- instance Flat (Diff a) => Flat (Diff (V2 a))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement