commutative-semigroups (empty) → 0.0.0.0
raw patch · 6 files changed
+167/−0 lines, 6 filesdep +basesetup-changed
Dependencies added: base
Files
- ChangeLog.md +5/−0
- LICENSE +31/−0
- ReadMe.md +9/−0
- Setup.hs +2/−0
- commutative-semigroups.cabal +28/−0
- src/Data/Semigroup/Commutative.hs +92/−0
+ ChangeLog.md view
@@ -0,0 +1,5 @@+# Revision history for commutative-semigroups++## Unreleased++Initial version, created from `groups` package.
+ LICENSE view
@@ -0,0 +1,31 @@+Copyright (c) 2013, Nathan "Taneb" van Doorn+ 2021, Obsidian Systems LLC++All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:++ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.++ * Redistributions in binary form must reproduce the above+ copyright notice, this list of conditions and the following+ disclaimer in the documentation and/or other materials provided+ with the distribution.++ * Neither the name of Nathan "Taneb" van Doorn nor the names of other+ contributors may be used to endorse or promote products derived+ from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ ReadMe.md view
@@ -0,0 +1,9 @@+# Commutative Semigroup++[](https://haskell.org) [](https://hackage.haskell.org/package/commutative-semigroup) [](https://matrix.hackage.haskell.org/#/package/commutative-semigroup) [](https://github.com/reflex-frp/commutative-semigroup/LICENSE)++A commutative semigroup is a semigroup where the order of arguments to mappend does not matter.++```haskell+class Semigroup g => Commutative g+```
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ commutative-semigroups.cabal view
@@ -0,0 +1,28 @@+cabal-version: 2.4+name: commutative-semigroups+version: 0.0.0.0+synopsis: Commutative semigroups+description:+ A commutative semigroup is a semigroup where the order of arguments to mappend does not matter.+license: BSD-3-Clause+license-file: LICENSE+author: Nathan "Taneb" van Doorn+maintainer: mainainer@obsidian.systems+copyright: Copyright (C) 2013 Nathan van Doorn, 2021 Obsidian Systems LLC+category: Algebra, Data, Math+build-type: Simple+bug-reports: https://github.com/ObsidianSystems/commutative-semigroups/issues+extra-source-files:+ ChangeLog.md+ ReadMe.md++source-repository head+ type: git+ location: https://github.com/ObsidianSystems/commutative-semigroups.git++library+ exposed-modules: Data.Semigroup.Commutative+ -- other-modules:+ build-depends: base >= 4.6 && < 5+ hs-source-dirs: src+ default-language: Haskell2010
+ src/Data/Semigroup/Commutative.hs view
@@ -0,0 +1,92 @@+{-# LANGUAGE CPP #-}+#if MIN_VERSION_base(4,12,0)+{-# LANGUAGE TypeOperators #-}+#endif++module Data.Semigroup.Commutative where++import Data.Monoid+import Data.Ord+import Data.List (unfoldr)+#if MIN_VERSION_base(4,7,0)+import Data.Proxy+#endif+#if MIN_VERSION_base(4,9,0) && !MIN_VERSION_base(4,11,0)+import Data.Semigroup (Semigroup(..))+#endif+#if MIN_VERSION_base(4,9,0)+import Data.Functor.Const+import Data.Functor.Identity+#endif+#if MIN_VERSION_base(4,12,0)+import Data.Functor.Contravariant (Op(Op))+import GHC.Generics+#endif++-- |An 'Commutative' semigroup is a 'Semigroup' that follows the rule:+--+-- @a \<> b == b \<> a@+class+#if MIN_VERSION_base(4,9,0)+ Semigroup g+#else+ Monoid g+#endif+ => Commutative g++-- | Trivial commutative semigroup.+instance Commutative ()++instance Num a => Commutative (Sum a)++instance Fractional a => Commutative (Product a)++instance Commutative a => Commutative (Dual a)++-- | Functions lift commutative semigroups pointwise.+instance Commutative b => Commutative (a -> b)++-- | Product commutative semigroup.+-- A Pair of commutative semigroups gives rise to a commutative semigroup+instance (Commutative a, Commutative b) => Commutative (a, b)++instance (Commutative a, Commutative b, Commutative c) => Commutative (a, b, c)++instance (Commutative a, Commutative b, Commutative c, Commutative d) => Commutative (a, b, c, d)++instance (Commutative a, Commutative b, Commutative c, Commutative d, Commutative e) => Commutative (a, b, c, d, e)++#if MIN_VERSION_base(4,11,0)+instance Commutative a => Commutative (Down a)+#endif++#if MIN_VERSION_base(4,7,0)+-- | Trivial commutative semigroup, Functor style.+instance Commutative (Proxy x)+#endif++-- 'Const' has existed for a long time, but the Monoid instance+-- arrives in base-4.9.0.0. Similarly, 'Identity' was defined in+-- base-4.8.0.0 but doesn't get the Monoid instance until base-4.9.0.0+#if MIN_VERSION_base(4,9,0)+-- | 'Const' lifts commutative semigroups into a functor.+instance Commutative a => Commutative (Const a x)++-- | 'Identity' lifts commutative semigroups pointwise (at only one point).+instance Commutative a => Commutative (Identity a)+#endif++-- (:*:) and (:.:) exist since base-4.6.0.0 but the Monoid instances+-- arrive in base-4.12.0.0.+-- Also, contravariant was moved into base in this version.+#if MIN_VERSION_base(4,12,0)+-- | Product of commutative semigroups, Functor style.+instance (Commutative (f a), Commutative (g a)) => Commutative ((f :*: g) a)++-- See https://gitlab.haskell.org/ghc/ghc/issues/11135#note_111802 for the reason Compose is not also provided.+-- Base does not define Monoid (Compose f g a) so this is the best we can+-- really do for functor composition.+instance Commutative (f (g a)) => Commutative ((f :.: g) a)++instance Commutative a => Commutative (Op a b)+#endif