Skip to content

Commit 2aaae42

Browse files
committed
Use groups package for group, a breaking change
TODO group's abelian should have Semigroup superclass. The MonoidalMap instance was deleted because it is not lawful. But it might need to be added to reflex. The version in the cabal file is bumped to remind whoever does the future release that this is breaking change. Closes #4.
1 parent 485c592 commit 2aaae42

File tree

3 files changed

+23
-83
lines changed

3 files changed

+23
-83
lines changed

ChangeLog.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Revision history for patch
22

3+
## Unreleased
4+
5+
* Reexport `Group` from the `groups` package instead of definining it here.
6+
7+
* Remove the `Group MonoidalMap` instance which is not lawful. `reflex` might
8+
provide it as an orphan for backwards compat, temporarily, but it should
9+
eventually be removed everywhere.
10+
11+
* `Applicative` is a now a type synnonym from `Abelian` from groups, which
12+
should work in constrants but might not in instances.
13+
14+
* Remove the `split-these` flag.
15+
We no longer need it as we only use the `These` datatype which is provided in all versions.
16+
317
## 0.0.3.2
418

519
* Update version bounds

patch.cabal

+3-14
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Name: patch
2-
Version: 0.0.3.2
2+
Version: 0.1.0.0
33
Synopsis: Data structures for describing changes to other data structures.
44
Description:
55
Data structures for describing changes to other data structures.
@@ -25,11 +25,6 @@ tested-with:
2525
GHC ==8.0.2 || ==8.2.2 || ==8.4.4 || ==8.6.5 || ==8.8.1
2626
GHCJS ==8.4
2727

28-
flag split-these
29-
description: Use split these/semialign packages
30-
manual: False
31-
default: True
32-
3328
library
3429
hs-source-dirs: src
3530
default-language: Haskell2010
@@ -38,8 +33,10 @@ library
3833
, containers >= 0.6 && < 0.7
3934
, dependent-map >= 0.3 && < 0.5
4035
, dependent-sum >= 0.6 && < 0.8
36+
, groups >= 0.5 && < 0.7
4137
, lens >= 4.7 && < 5
4238
, semigroupoids >= 4.0 && < 6
39+
, these >= 0.4 && < 1.2
4340
, transformers >= 0.5.6.0 && < 0.6
4441
, witherable >= 0.3 && < 0.4
4542

@@ -56,14 +53,6 @@ library
5653

5754
ghc-options: -Wall -fwarn-redundant-constraints -fwarn-tabs
5855

59-
if flag(split-these)
60-
build-depends: these >= 1 && <1.2
61-
, semialign >=1 && <1.2
62-
, monoidal-containers >= 0.6 && < 0.7
63-
else
64-
build-depends: these >= 0.4 && <0.9
65-
, monoidal-containers == 0.4.0.0
66-
6756
test-suite hlint
6857
default-language: Haskell2010
6958
type: exitcode-stdio-1.0

src/Data/Patch.hs

+6-69
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{-# LANGUAGE CPP #-}
2-
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
3-
{-# LANGUAGE StandaloneDeriving #-}
2+
{-# LANGUAGE ConstraintKinds #-}
43
{-# LANGUAGE TypeFamilies #-}
5-
{-# LANGUAGE TypeOperators #-}
64
-- |
75
-- Module:
86
-- Data.Patch
@@ -11,17 +9,13 @@
119
module Data.Patch
1210
( module Data.Patch
1311
, module X
12+
, Group (..)
1413
) where
1514

16-
import Control.Applicative
17-
import Data.Functor.Const (Const (..))
18-
import Data.Functor.Identity
19-
import Data.Map.Monoidal (MonoidalMap)
20-
import Data.Proxy
15+
import Data.Group
2116
#if !MIN_VERSION_base(4,11,0)
22-
import Data.Semigroup (Semigroup (..))
17+
import Data.Semigroup (<>)
2318
#endif
24-
import GHC.Generics
2519

2620
import Data.Patch.Class as X
2721
import Data.Patch.DMap as X hiding (getDeletions)
@@ -39,68 +33,11 @@ import Data.Patch.MapWithMove as X
3933
, unsafePatchMapWithMove
4034
)
4135

42-
-- | A 'Group' is a 'Monoid' where every element has an inverse.
43-
class (Semigroup q, Monoid q) => Group q where
44-
negateG :: q -> q
45-
(~~) :: q -> q -> q
46-
r ~~ s = r <> negateG s
47-
48-
-- | An 'Additive' 'Semigroup' is one where (<>) is commutative
49-
class Semigroup q => Additive q where
36+
type Additive = Abelian
5037

5138
-- | The elements of an 'Additive' 'Semigroup' can be considered as patches of their own type.
5239
newtype AdditivePatch p = AdditivePatch { unAdditivePatch :: p }
5340

54-
instance Additive p => Patch (AdditivePatch p) where
41+
instance Abelian p => Patch (AdditivePatch p) where
5542
type PatchTarget (AdditivePatch p) = p
5643
apply (AdditivePatch p) q = Just $ p <> q
57-
58-
instance (Ord k, Group q) => Group (MonoidalMap k q) where
59-
negateG = fmap negateG
60-
61-
instance (Ord k, Additive q) => Additive (MonoidalMap k q)
62-
63-
-- | Trivial group.
64-
instance Group () where
65-
negateG _ = ()
66-
_ ~~ _ = ()
67-
instance Additive ()
68-
69-
-- | Product group. A Pair of groups gives rise to a group
70-
instance (Group a, Group b) => Group (a, b) where
71-
negateG (a, b) = (negateG a, negateG b)
72-
(a, b) ~~ (c, d) = (a ~~ c, b ~~ d)
73-
instance (Additive a, Additive b) => Additive (a, b)
74-
75-
-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.
76-
-- Base does not define Monoid (Compose f g a) so this is the best we can
77-
-- really do for functor composition.
78-
instance Group (f (g a)) => Group ((f :.: g) a) where
79-
negateG (Comp1 xs) = Comp1 (negateG xs)
80-
Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys)
81-
instance Additive (f (g a)) => Additive ((f :.: g) a)
82-
83-
-- | Product of groups, Functor style.
84-
instance (Group (f a), Group (g a)) => Group ((f :*: g) a) where
85-
negateG (a :*: b) = negateG a :*: negateG b
86-
(a :*: b) ~~ (c :*: d) = (a ~~ c) :*: (b ~~ d)
87-
instance (Additive (f a), Additive (g a)) => Additive ((f :*: g) a)
88-
89-
-- | Trivial group, Functor style
90-
instance Group (Proxy x) where
91-
negateG _ = Proxy
92-
_ ~~ _ = Proxy
93-
instance Additive (Proxy x)
94-
95-
-- | Const lifts groups into a functor.
96-
deriving instance Group a => Group (Const a x)
97-
instance Additive a => Additive (Const a x)
98-
-- | Ideitnty lifts groups pointwise (at only one point)
99-
deriving instance Group a => Group (Identity a)
100-
instance Additive a => Additive (Identity a)
101-
102-
-- | Functions lift groups pointwise.
103-
instance Group b => Group (a -> b) where
104-
negateG f = negateG . f
105-
(~~) = liftA2 (~~)
106-
instance Additive b => Additive (a -> b)

0 commit comments

Comments
 (0)