commutative-semigroups 0.0.2.0 → 0.1.0.0
raw patch · 4 files changed
+129/−2 lines, 4 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.Semigroup.Commutative: instance GHC.Real.Fractional a => Data.Semigroup.Commutative.Commutative (Data.Semigroup.Internal.Product a)
+ Data.Semigroup.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Data.Semigroup.Commutative.Commutative (Data.Semigroup.Internal.Product a)
+ Numeric.Product.Commutative: class Num a => CommutativeProduct a
+ Numeric.Product.Commutative: instance (Data.Fixed.HasResolution a, Numeric.Product.Commutative.CommutativeProduct a) => Numeric.Product.Commutative.CommutativeProduct (Data.Fixed.Fixed a)
+ Numeric.Product.Commutative: instance (GHC.Float.RealFloat a, Numeric.Product.Commutative.CommutativeProduct a) => Numeric.Product.Commutative.CommutativeProduct (Data.Complex.Complex a)
+ Numeric.Product.Commutative: instance (GHC.Real.Integral a, Numeric.Product.Commutative.CommutativeProduct a) => Numeric.Product.Commutative.CommutativeProduct (GHC.Real.Ratio a)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct (f a) => Numeric.Product.Commutative.CommutativeProduct (Data.Semigroup.Internal.Alt f a)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Int.Int16
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Int.Int32
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Int.Int64
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Int.Int8
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Integer.Type.Integer
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Natural.Natural
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Types.Double
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Types.Float
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Types.Int
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Types.Word
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Word.Word16
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Word.Word32
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Word.Word64
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct GHC.Word.Word8
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Functor.Const.Const a b)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Functor.Contravariant.Op a b)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Functor.Identity.Identity a)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Ord.Down a)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Semigroup.Internal.Product a)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Semigroup.Internal.Sum a)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Semigroup.Max a)
+ Numeric.Product.Commutative: instance Numeric.Product.Commutative.CommutativeProduct a => Numeric.Product.Commutative.CommutativeProduct (Data.Semigroup.Min a)
Files
- ChangeLog.md +21/−0
- commutative-semigroups.cabal +2/−1
- src/Data/Semigroup/Commutative.hs +2/−1
- src/Numeric/Product/Commutative.hs +104/−0
ChangeLog.md view
@@ -1,5 +1,26 @@ # Revision history for commutative-semigroups +## 0.1.0.0 -- 2022-06-12++- `Commutative (Product a)` now requires `CommutativeProduct a`.+ `CommutativeProduct` is a new class to indicate `(*)` from `Num` is+ commutative, which is not required by `Num`. (Example:+ multiplication on+ [quaternions](https://en.wikipedia.org/wiki/Quaternion) is+ non-commutative, and the `Quaternion a` type from the `linear`+ package has a valid `instance RealFloat a => Num (Quaternion a)`.)++ **Remark:** There is also no canonical subclass class in the `Num`+ hierarchy which implies commutative `(*)`, as both `Integral` and+ `Floating` instances work here:++ - `Integral` instances are customarily Euclidean Domains, which are+ commutative rings with extra conditions.++ - `Floating` instances customarily expect `(+)`, `(*)`, and `exp` to+ form an exponential field, which is also a commutative ring with+ extra conditions.+ ## 0.0.2.0 -- 2022-03-26 - Add `instance Ord a => Commutative (Set a)`
commutative-semigroups.cabal view
@@ -1,6 +1,6 @@ cabal-version: 2.4 name: commutative-semigroups-version: 0.0.2.0+version: 0.1.0.0 synopsis: Commutative semigroups description: A commutative semigroup is a semigroup where the order of arguments to mappend does not matter.@@ -22,6 +22,7 @@ library exposed-modules: Data.Semigroup.Commutative+ Numeric.Product.Commutative -- other-modules: build-depends: base >= 4.6 && < 4.17, containers >= 0.4 && < 0.7
src/Data/Semigroup/Commutative.hs view
@@ -24,6 +24,7 @@ import Data.Functor.Contravariant (Op(Op)) import GHC.Generics #endif+import Numeric.Product.Commutative ( CommutativeProduct ) -- |An 'Commutative' semigroup is a 'Semigroup' that follows the rule: --@@ -44,7 +45,7 @@ instance Num a => Commutative (Sum a) -instance Fractional a => Commutative (Product a)+instance CommutativeProduct a => Commutative (Product a) instance Commutative a => Commutative (Dual a)
+ src/Numeric/Product/Commutative.hs view
@@ -0,0 +1,104 @@+{-# LANGUAGE CPP #-}+module Numeric.Product.Commutative+ ( CommutativeProduct (..)+ )+ where++import Control.Applicative (Const)+import Data.Complex (Complex)+import Data.Fixed+import Data.Functor.Identity+import Data.Int+import Data.Ratio (Ratio)+import Data.Word+import Numeric.Natural++#if MIN_VERSION_base(4, 9, 0)+import Data.Semigroup (Max, Min, Product, Sum)+#endif++#if MIN_VERSION_base(4, 11, 0)+import Data.Ord (Down)+#endif++#if MIN_VERSION_base(4, 12, 0)+import Data.Functor.Contravariant (Op)+import Data.Monoid (Alt)+#endif++-- | Subclass of 'Num' where '(*)' is commutative.+--+-- 'Num' doesn't demand commutative '(*)', and there are reasonable+-- "real-world" instances with non-commutative multiplication. There+-- is also no canonical subclass in @base@ that would suffice, as both+-- 'Integral' and 'Floating' imply commutative '(*)' for different+-- reasons.+--+-- Two examples of non-commutative '(*)':+--+-- * @Linear.Quaternion.Quaterion@ from the @linear@ package has a+-- 'Num' instance, and quaternion multiplication is+-- noncommutative.+--+-- * @Data.Matrix.Matrix@ from the @matrix@ package uses '(*)' for+-- matrix multiplication, which is also non-commutative (on square+-- matrices, which is the only time the question makes sense).+--+-- @since 0.1.0+class Num a => CommutativeProduct a++instance CommutativeProduct Int8+instance CommutativeProduct Int16+instance CommutativeProduct Int32+instance CommutativeProduct Int64+instance CommutativeProduct Int+instance CommutativeProduct Integer++instance CommutativeProduct Word8+instance CommutativeProduct Word16+instance CommutativeProduct Word32+instance CommutativeProduct Word64+instance CommutativeProduct Word+instance CommutativeProduct Natural++instance CommutativeProduct Float+instance CommutativeProduct Double++instance (RealFloat a, CommutativeProduct a) => CommutativeProduct (Complex a)++instance CommutativeProduct a => CommutativeProduct (Identity a)++-- @since: base-4.7.0.0+instance CommutativeProduct a => CommutativeProduct (Sum a)++-- @since: base-4.7.0.0+instance (Integral a, CommutativeProduct a) => CommutativeProduct (Ratio a)++instance (HasResolution a, CommutativeProduct a) => CommutativeProduct (Fixed a)++#if MIN_VERSION_base(4, 9, 0)+-- @since: base-4.9.0.0+instance CommutativeProduct a => CommutativeProduct (Min a)++-- @since: base-4.9.0.0+instance CommutativeProduct a => CommutativeProduct (Max a)++-- @since: base-4.9.0.0+instance CommutativeProduct a => CommutativeProduct (Product a)++-- @since: base-4.9.0.0+instance CommutativeProduct a => CommutativeProduct (Const a b)+#endif++#if MIN_VERSION_base(4, 11, 0)+-- @since: base-4.11.0.0+instance CommutativeProduct a => CommutativeProduct (Down a)+#endif++#if MIN_VERSION_base(4, 12, 0)+-- @since: base-4.12.0.0+instance CommutativeProduct a => CommutativeProduct (Op a b)++-- @since: base-4.12.0.0+instance CommutativeProduct (f a) => CommutativeProduct (Alt f a)+#endif