on develop help sign in
Move `Additive` to its own module
830add4John Ericson
ChangeLog.md+3
@@ -15,6 +15,9 @@
15* `Applicative` is still defined, because the `Abelian` from `groups` has too
15* `Applicative` is still defined, because the `Abelian` from `groups` has too
16 stringent a constraint.
16 stringent a constraint.
17
17
18+* `Additive` now lives in `Data.Semigroup.Additive`, but is still reexported
19+ from `Data.Patch` for compatability.
20+
18## 0.0.3.2
21## 0.0.3.2
19
22
20* Update version bounds
23* Update version bounds
patch.cabal+1
@@ -49,6 +49,7 @@ library
49 , Data.Patch.Map
49 , Data.Patch.Map
50 , Data.Patch.MapWithMove
50 , Data.Patch.MapWithMove
51 , Data.Patch.MapWithPatchingMove
51 , Data.Patch.MapWithPatchingMove
52+ , Data.Semigroup.Additive
52
53
53 ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs
54 ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs
54
55
src/Data/Patch.hs+1−32
@@ -11,14 +11,11 @@ module Data.Patch
11 , module X
11 , module X
12 ) where
12 ) where
13
13
14−import Data.Functor.Const (Const (..))
15−import Data.Functor.Identity
16−import Data.Proxy
17#if !MIN_VERSION_base(4,11,0)
14#if !MIN_VERSION_base(4,11,0)
18import Data.Semigroup (Semigroup (..))
15import Data.Semigroup (Semigroup (..))
19#endif
16#endif
20−import GHC.Generics
21
17
18+import Data.Semigroup.Additive as X
22import Data.Patch.Class as X
19import Data.Patch.Class as X
23import Data.Patch.DMap as X hiding (getDeletions)
20import Data.Patch.DMap as X hiding (getDeletions)
24import Data.Patch.DMapWithMove as X
21import Data.Patch.DMapWithMove as X
@@ -35,37 +32,9 @@ import Data.Patch.MapWithMove as X
35 , unsafePatchMapWithMove
32 , unsafePatchMapWithMove
36 )
33 )
37
34
38−-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
39−class Semigroup q => Additive q where
40−
41-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
35-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
42newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
36newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
43
37
44instance Additive p => Patch (AdditivePatch p) where
38instance Additive p => Patch (AdditivePatch p) where
45 type PatchTarget (AdditivePatch p) = p
39 type PatchTarget (AdditivePatch p) = p
46 apply (AdditivePatch p) q = Just $ p <> q
40 apply (AdditivePatch p) q = Just $ p <> q
47−
48−-- | Trivial group.
49−instance Additive ()
50−
51−-- | Product group. A Pair of groups gives rise to a group
52−instance (Additive a, Additive b) => Additive (a, b)
53−
54−-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
55−-- Base does not define Monoid (Compose f g a) so this is the best we can
56−-- really do for functor composition.
57−instance Additive (f (g a)) => Additive ((f :.: g) a)
58−
59−-- | Product of groups, Functor style.
60−instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
61−
62−-- | Trivial group, Functor style
63−instance Additive (Proxy x)
64−
65−-- | Const lifts groups into a functor.
66−instance Additive a => Additive (Const a x)
67−-- | Ideitnty lifts groups pointwise (at only one point)
68−instance Additive a => Additive (Identity a)
69−
70−-- | Functions lift groups pointwise.
71−instance Additive b => Additive (a -> b)
src/Data/Semigroup/Additive.hsnew file+48
@@ -0,0 +1,48 @@
1+{-# LANGUAGE CPP #-}
2+{-# LANGUAGE TypeOperators #-}
3+{-# LANGUAGE TypeFamilies #-}
4+-- |
5+-- Module:
6+-- Data.Semigroup.Additive
7+-- Description:
8+-- This module defines a class for commutative semigroups, until it is moved
9+-- to another library.
10+module Data.Semigroup.Additive
11+ ( Additive
12+ ) where
13+
14+import Data.Functor.Const (Const (..))
15+import Data.Functor.Identity
16+import Data.Proxy
17+#if !MIN_VERSION_base(4,11,0)
18+import Data.Semigroup (Semigroup (..))
19+#endif
20+import GHC.Generics
21+
22+-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
23+class Semigroup q => Additive q where
24+
25+-- | Trivial group.
26+instance Additive ()
27+
28+-- | Product group. A Pair of groups gives rise to a group
29+instance (Additive a, Additive b) => Additive (a, b)
30+
31+-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
32+-- Base does not define Monoid (Compose f g a) so this is the best we can
33+-- really do for functor composition.
34+instance Additive (f (g a)) => Additive ((f :.: g) a)
35+
36+-- | Product of groups, Functor style.
37+instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
38+
39+-- | Trivial group, Functor style
40+instance Additive (Proxy x)
41+
42+-- | Const lifts groups into a functor.
43+instance Additive a => Additive (Const a x)
44+-- | Ideitnty lifts groups pointwise (at only one point)
45+instance Additive a => Additive (Identity a)
46+
47+-- | Functions lift groups pointwise.
48+instance Additive b => Additive (a -> b)