Skip to content

Commit 253fd3f

Browse files
committed
Move Additive to its own module
1 parent 6be4716 commit 253fd3f

File tree

4 files changed

+53
-32
lines changed

4 files changed

+53
-32
lines changed

ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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)
1815
import Data.Semigroup (Semigroup (..))
1916
#endif
20-
import GHC.Generics
2117

18+
import Data.Semigroup.Additive as X
2219
import Data.Patch.Class as X
2320
import Data.Patch.DMap as X hiding (getDeletions)
2421
import 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.
4236
newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
4337

4438
instance 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.hs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

0 commit comments

Comments
 (0)