diff --git a/.github/workflows/haskell.yml b/.github/workflows/haskell.yml index 6a52bed..8273cf2 100644 --- a/.github/workflows/haskell.yml +++ b/.github/workflows/haskell.yml @@ -19,7 +19,7 @@ jobs: name: GHC ${{ matrix.ghc }} on ${{ matrix.os }} steps: - uses: actions/checkout@v2 - - uses: actions/setup-haskell@v1 + - uses: haskell/actions/setup@v1 with: ghc-version: ${{ matrix.ghc }} - name: Cache diff --git a/ChangeLog.md b/ChangeLog.md index f88176e..c8d1c4d 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,5 +1,11 @@ # Revision history for groups +## Unreleased + +* `Abelian` is now just a small wrapper around `Group` + `Commutative` from + `commutative-semigroups`, which was forked out from this library to relax the + superclass. + ## 0.5.3 - 2021-05-14 * Fix bug in `generated'` diff --git a/groups.cabal b/groups.cabal index df1a273..a36caf5 100644 --- a/groups.cabal +++ b/groups.cabal @@ -23,5 +23,6 @@ library exposed-modules: Data.Group -- other-modules: build-depends: base >= 4.6 && < 5 + , commutative-semigroups >= 0.0 && < 0.1 hs-source-dirs: src default-language: Haskell2010 diff --git a/src/Data/Group.hs b/src/Data/Group.hs index 6aec99e..5a010dd 100644 --- a/src/Data/Group.hs +++ b/src/Data/Group.hs @@ -1,11 +1,14 @@ -{-# LANGUAGE CPP #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE UndecidableInstances #-} #if MIN_VERSION_base(4,12,0) -{-# LANGUAGE TypeOperators #-} +{-# LANGUAGE TypeOperators #-} #endif module Data.Group where import Data.Monoid +import Data.Semigroup.Commutative import Data.Ord import Data.List (unfoldr) #if MIN_VERSION_base(4,7,0) @@ -98,32 +101,9 @@ instance Group a => Group (Down a) where invert (Down a) = Down (invert a) #endif --- |An 'Abelian' group is a 'Group' that follows the rule: --- --- @a \<> b == b \<> a@ -class Group g => Abelian g - -instance Abelian () - -instance Num a => Abelian (Sum a) - -instance Fractional a => Abelian (Product a) - -instance Abelian a => Abelian (Dual a) - -instance Abelian b => Abelian (a -> b) - -instance (Abelian a, Abelian b) => Abelian (a, b) - -instance (Abelian a, Abelian b, Abelian c) => Abelian (a, b, c) - -instance (Abelian a, Abelian b, Abelian c, Abelian d) => Abelian (a, b, c, d) - -instance (Abelian a, Abelian b, Abelian c, Abelian d, Abelian e) => Abelian (a, b, c, d, e) - -#if MIN_VERSION_base(4,11,0) -instance Abelian a => Abelian (Down a) -#endif +-- |An 'Abelian' group is a 'Group' that is also 'Commutative' +class (Group g, Commutative g) => Abelian g +instance (Group g, Commutative g) => Abelian g -- | A 'Group' G is 'Cyclic' if there exists an element x of G such that for all y in G, there exists an n, such that -- @@ -163,8 +143,6 @@ instance Group (Proxy x) where _ ~~ _ = Proxy pow _ _ = Proxy -instance Abelian (Proxy x) - instance Cyclic (Proxy x) where generator = Proxy #endif @@ -183,10 +161,6 @@ instance Group a => Group (Identity a) where invert (Identity a) = Identity (invert a) Identity a ~~ Identity b = Identity (a ~~ b) -instance Abelian a => Abelian (Const a x) - -instance Abelian a => Abelian (Identity a) - instance Cyclic a => Cyclic (Const a x) where generator = Const generator @@ -210,15 +184,9 @@ instance Group (f (g a)) => Group ((f :.: g) a) where invert (Comp1 xs) = Comp1 (invert xs) Comp1 xs ~~ Comp1 ys = Comp1 (xs ~~ ys) -instance (Abelian (f a), Abelian (g a)) => Abelian ((f :*: g) a) - -instance Abelian (f (g a)) => Abelian ((f :.: g) a) - instance Group a => Group (Op a b) where invert (Op f) = Op (invert f) pow (Op f) n = Op (\e -> pow (f e) n) - -instance Abelian a => Abelian (Op a b) #endif #if MIN_VERSION_base(4,11,0)