@@ -1,45 +0,0 @@
1−{-# LANGUAGE DeriveGeneric #-}
2−{-# LANGUAGE FlexibleContexts #-}
3−{-# LANGUAGE LambdaCase #-}
4−{-# LANGUAGE StandaloneDeriving #-}
5−{-# LANGUAGE TypeFamilies #-}
6−
7−-- The derived instances are undecidable in the case of a pathological instance like
8−-- instance Patch x where
9−-- type PatchTarget x = Patchable x
10−{-# LANGUAGE UndecidableInstances #-}
11−
12−module Data.Patch.Patchable where
13−
14−-- import Data.Aeson
15−import GHC.Generics
16−
17−import Data.Patch
18−
19−-- | Like SemiMap/PartialMap but for anything patchable
20−data Patchable p
21− = Patchable_Patch p
22− | Patchable_Complete (PatchTarget p)
23− deriving (Generic)
24−
25−completePatchable :: Patchable p -> Maybe (PatchTarget p)
26−completePatchable = \case
27− Patchable_Complete t -> Just t
28− Patchable_Patch _ -> Nothing
29−
30−deriving instance (Eq p, Eq (PatchTarget p)) => Eq (Patchable p)
31−deriving instance (Ord p, Ord (PatchTarget p)) => Ord (Patchable p)
32−deriving instance (Show p, Show (PatchTarget p)) => Show (Patchable p)
33−deriving instance (Read p, Read (PatchTarget p)) => Read (Patchable p)
34−-- instance (ToJSON p, ToJSON (PatchTarget p)) => ToJSON (Patchable p)
35−-- instance (FromJSON p, FromJSON (PatchTarget p)) => FromJSON (Patchable p)
36−
37−instance (Monoid p, Patch p) => Monoid (Patchable p) where
38− mempty = Patchable_Patch mempty
39− mappend = (<>)
40−
41−instance (Semigroup p, Patch p) => Semigroup (Patchable p) where
42− (<>) = curry $ \case
43− (Patchable_Patch a, Patchable_Patch b) -> Patchable_Patch $ a <> b
44− (Patchable_Patch a, Patchable_Complete b) -> Patchable_Complete $ applyAlways a b
45− (Patchable_Complete a, _) -> Patchable_Complete a