Skip to content

Commit

Permalink
Merge pull request Taneb#14 from obsidiansystems/use-commutative-semi…
Browse files Browse the repository at this point in the history
…groups

Use `communitative-semigroup` and make `Abelian` small wrapper
  • Loading branch information
Taneb authored Mar 26, 2022
2 parents df02bb8 + 0f2a452 commit dcc1177
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/haskell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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'`
Expand Down
1 change: 1 addition & 0 deletions groups.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
48 changes: 8 additions & 40 deletions src/Data/Group.hs
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
--
Expand Down Expand Up @@ -163,8 +143,6 @@ instance Group (Proxy x) where
_ ~~ _ = Proxy
pow _ _ = Proxy

instance Abelian (Proxy x)

instance Cyclic (Proxy x) where
generator = Proxy
#endif
Expand All @@ -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

Expand All @@ -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)
Expand Down

0 comments on commit dcc1177

Please sign in to comment.