Skip to content

Commit e0aee68

Browse files
authored
Merge pull request #39 from reflex-frp/use-commutative-semigroups
Factor out Additive
2 parents b4f8f06 + b6da47c commit e0aee68

File tree

4 files changed

+15
-46
lines changed

4 files changed

+15
-46
lines changed

ChangeLog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Revision history for patch
22

3+
## Unreleased
4+
5+
* Use `commutative-semigroups` for `Commutative`, making `Additive` a
6+
deprecated alias.
7+
38
## 0.0.6.0 - 2022-06-10
49

510
* Add `PatchOrReplacement`, patch which either is some other patch type or a

patch.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ library
3535
default-language: Haskell2010
3636
build-depends: base >= 4.9 && < 4.17
3737
, constraints-extras >= 0.3 && < 0.4
38+
, commutative-semigroups >= 0.0 && < 0.2
3839
, containers >= 0.6 && < 0.7
3940
, dependent-map >= 0.3 && < 0.5
4041
, dependent-sum >= 0.6 && < 0.8

src/Data/Patch.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module Data.Patch
1313
, module X
1414
) where
1515

16+
import Data.Semigroup.Commutative
1617
import Control.Applicative (liftA2)
1718
import Data.Functor.Const (Const (..))
1819
import Data.Functor.Identity
@@ -23,7 +24,7 @@ import Data.Semigroup (Semigroup (..))
2324
#endif
2425
import GHC.Generics
2526

26-
import Data.Semigroup.Additive as X
27+
import qualified Data.Semigroup.Additive as X
2728
import Data.Patch.Class as X
2829
import Data.Patch.DMap as X hiding (getDeletions)
2930
import Data.Patch.DMapWithMove as X
@@ -46,10 +47,10 @@ class (Semigroup q, Monoid q) => Group q where
4647
(~~) :: q -> q -> q
4748
r ~~ s = r <> negateG s
4849

49-
-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
50+
-- | The elements of an 'Commutative' 'Semigroup' can be considered as patches of their own type.
5051
newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
5152

52-
instance Additive p => Patch (AdditivePatch p) where
53+
instance Commutative p => Patch (AdditivePatch p) where
5354
type PatchTarget (AdditivePatch p) = p
5455
apply (AdditivePatch p) q = Just $ p <> q
5556

src/Data/Semigroup/Additive.hs

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,14 @@
1-
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE TypeOperators #-}
3-
{-# LANGUAGE TypeFamilies #-}
1+
{-# LANGUAGE ConstraintKinds #-}
42

53
{-|
64
Description : A class for commutative semigroups
75
-}
86
module Data.Semigroup.Additive
7+
{-# DEPRECATED "Use 'Data.Semigroup.Commutative'" #-}
98
( Additive
109
) where
1110

12-
import Data.Functor.Const (Const (..))
13-
import Data.Functor.Identity
14-
import Data.Proxy
15-
#if !MIN_VERSION_base(4,12,0)
16-
-- for :*: and :.: semigroup instances
17-
import Data.Orphans ()
18-
#endif
19-
#if !MIN_VERSION_base(4,11,0)
20-
import Data.Semigroup (Semigroup (..))
21-
#endif
22-
import GHC.Generics
11+
import Data.Semigroup.Commutative
2312

24-
-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
25-
class Semigroup q => Additive q where
26-
27-
-- | Trivial additive semigroup.
28-
instance Additive ()
29-
30-
-- | Product additive semigroup.
31-
-- A Pair of additive semigroups gives rise to a additive semigroup
32-
instance (Additive a, Additive b) => Additive (a, b)
33-
34-
-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
35-
-- Base does not define Monoid (Compose f g a) so this is the best we can
36-
-- really do for functor composition.
37-
instance Additive (f (g a)) => Additive ((f :.: g) a)
38-
39-
-- | Product of additive semigroups, Functor style.
40-
instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
41-
42-
-- | Trivial additive semigroup, Functor style
43-
instance Additive (Proxy x)
44-
45-
-- | Const lifts additive semigroups into a functor.
46-
instance Additive a => Additive (Const a x)
47-
48-
-- | Identity lifts additive semigroups pointwise (at only one point)
49-
instance Additive a => Additive (Identity a)
50-
51-
-- | Functions lift additive semigroups pointwise.
52-
instance Additive b => Additive (a -> b)
13+
{-# DEPRECATED Additive "Use 'Data.Semigroup.Commutative.Commutative'" #-}
14+
type Additive = Commutative

0 commit comments

Comments
 (0)