patch 0.0.0.1 → 0.0.1.0
raw patch · 3 files changed
+73/−4 lines, 3 filesdep ~monoidal-containersdep ~these
Dependency ranges changed: monoidal-containers, these
Files
- ChangeLog.md +6/−0
- patch.cabal +14/−4
- src/Data/Patch.hs +53/−0
ChangeLog.md view
@@ -1,5 +1,11 @@ # Revision history for patch +## 0.0.1.0++* Support older GHCs with `split-these` flag.++* Additional instances for the `Group` class for basic types.+ ## 0.0.0.1 * Remove unneeded dependencies
patch.cabal view
@@ -1,5 +1,5 @@ Name: patch-Version: 0.0.0.1+Version: 0.0.1.0 Synopsis: Infrastructure for writing patches which act on other types. Description: In this library, a patch is something which can be applied, analogous to a@@ -23,6 +23,11 @@ GHC ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1 GHCJS ==8.4 +flag split-these+ description: Use split these/semialign packages+ manual: False+ default: True+ library hs-source-dirs: src build-depends: base >= 4.9 && < 4.14@@ -30,10 +35,7 @@ , containers >= 0.6 && < 0.7 , dependent-map >= 0.3 && < 0.4 , dependent-sum >= 0.6 && < 0.7- , monoidal-containers >= 0.6 && < 0.7- , semialign >=1 && <1.2 , semigroupoids >= 4.0 && < 6- , these >= 1 && <1.1 , transformers >= 0.5.6.0 && < 0.6 , witherable >= 0.3 && < 0.3.2 @@ -47,6 +49,14 @@ , Data.Patch.MapWithMove ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs++ if flag(split-these)+ build-depends: these >= 1 && <1.1+ , semialign >=1 && <1.2+ , monoidal-containers >= 0.6 && < 0.7+ else+ build-depends: these >= 0.4 && <0.9+ , monoidal-containers == 0.4.0.0 test-suite hlint type: exitcode-stdio-1.0
src/Data/Patch.hs view
@@ -1,4 +1,7 @@+{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-} -- | -- Module: -- Data.Patch@@ -22,6 +25,11 @@ unsafePatchMapWithMove) import Data.Map.Monoidal (MonoidalMap) import Data.Semigroup (Semigroup (..), (<>))+import GHC.Generics+import Data.Functor.Identity+import Data.Functor.Const+import Data.Proxy+import Control.Applicative -- | A 'Group' is a 'Monoid' where every element has an inverse. class (Semigroup q, Monoid q) => Group q where@@ -43,3 +51,48 @@ negateG = fmap negateG instance (Ord k, Additive q) => Additive (MonoidalMap k q)++-- | Trivial group.+instance Group () where+ negateG _ = ()+ _ ~~ _ = ()+instance Additive ()++-- | Product group. A Pair of groups gives rise to a group+instance (Group a, Group b) => Group (a, b) where+ negateG (a, b) = (negateG a, negateG b)+ (a, b) ~~ (c, d) = (a ~~ c, b ~~ d)+instance (Additive a, Additive b) => Additive (a, b)++-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.+-- Base does not define Monoid (Compose f g a) so this is the best we can+-- really do for functor composition.+instance Group (f (g a)) => Group ((f :.: g) a) where+ negateG (Comp1 xs) = Comp1 (negateG xs)+ Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)+instance Additive (f (g a)) => Additive ((f :.: g) a)++-- | Product of groups, Functor style.+instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where+ negateG (a :*: b) = negateG a :*: negateG b+ (a :*: b) ~~ (c :*: d) = (a ~~ c) :*: (b ~~ d)+instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)++-- | Trivial group, Functor style+instance Group (Proxy x) where+ negateG _ = Proxy+ _ ~~ _ = Proxy+instance Additive (Proxy x)++-- | Const lifts groups into a functor.+deriving instance Group a => Group (Const a x)+instance Additive a => Additive (Const a x)+-- | Ideitnty lifts groups pointwise (at only one point)+deriving instance Group a => Group (Identity a)+instance Additive a => Additive (Identity a)++-- | Functions lift groups pointwise.+instance Group b => Group (a -> b) where+ negateG f = negateG . f+ (~~) = liftA2 (~~)+instance Additive b => Additive (a -> b)