on develop help sign in
Move `Additive` to its own module
commit830add423b76b7b838966769f14b212733ac7c23 authorJohn Ericson <John.Ericson@Obsidian.Systems> dateFri 11 Dec 2020, 15:00 (6 years ago) parentf6d4c9a
4 files changed+53−32
ChangeLog.md+3 patch.cabal+1 src/Data/Patch.hs+1−32 src/Data/Semigroup/Additive.hs+48
ChangeLog.md+3
@@ -15,6 +15,9 @@
1515* `Applicative` is still defined, because the `Abelian` from `groups` has too
1616 stringent a constraint.
1717
18+* `Additive` now lives in `Data.Semigroup.Additive`, but is still reexported
19+ from `Data.Patch` for compatability.
20+
1821## 0.0.3.2
1922
2023* Update version bounds
patch.cabal+1
@@ -49,6 +49,7 @@ library
4949 , Data.Patch.Map
5050 , Data.Patch.MapWithMove
5151 , Data.Patch.MapWithPatchingMove
52+ , Data.Semigroup.Additive
5253
5354 ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs
5455
src/Data/Patch.hs+1−32
@@ -11,14 +11,11 @@ module Data.Patch
1111 , module X
1212 ) where
1313
14−import Data.Functor.Const (Const (..))
15−import Data.Functor.Identity
16−import Data.Proxy
1714#if !MIN_VERSION_base(4,11,0)
1815import Data.Semigroup (Semigroup (..))
1916#endif
20−import GHC.Generics
2117
18+import Data.Semigroup.Additive as X
2219import Data.Patch.Class as X
2320import Data.Patch.DMap as X hiding (getDeletions)
2421import Data.Patch.DMapWithMove as X
@@ -35,37 +32,9 @@ import Data.Patch.MapWithMove as X
3532 , unsafePatchMapWithMove
3633 )
3734
38−-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
39−class Semigroup q => Additive q where
40−
4135-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
4236newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
4337
4438instance Additive p => Patch (AdditivePatch p) where
4539 type PatchTarget (AdditivePatch p) = p
4640 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)