packages feed

numhask 0.11.0.2 → 0.11.1.0

raw patch · 6 files changed

+161/−135 lines, 6 files

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright Tony Day (c) 2016+Copyright (c) 2016, Tony Day  All rights reserved. 
numhask.cabal view
@@ -1,141 +1,138 @@-cabal-version:      3.0-name:               numhask-version:            0.11.0.2-synopsis:           A numeric class hierarchy.+cabal-version: 3.0+name: numhask+version: 0.11.1.0+license: BSD-3-Clause+license-file: LICENSE+copyright: Tony Day (c) 2016+category: math+author: Tony Day+maintainer: tonyday567@gmail.com+homepage: https://github.com/tonyday567/numhask#readme+bug-reports: https://github.com/tonyday567/numhask/issues+synopsis: A numeric class hierarchy. description:-  This package provides alternative numeric classes over Prelude.+    This package provides alternative numeric classes over Prelude. -  The numeric class constellation looks somewhat like:+    The numeric class constellation looks somewhat like: -  ![nh](docs/other/nh.svg)+    ![nh](docs/other/nh.svg) -  == Usage+    == Usage -  >>> {-# LANGUAGE GHC2021 #-}-  >>> {-# LANGUAGE RebindableSyntax #-}-  >>> import NumHask.Prelude+    >>> {-# LANGUAGE GHC2021 #-}+    >>> {-# LANGUAGE RebindableSyntax #-}+    >>> import NumHask.Prelude -  See "NumHask" for a detailed overview.+    See "NumHask" for a detailed overview. -category:           mathematics-homepage:           https://github.com/tonyday567/numhask#readme-bug-reports:        https://github.com/tonyday567/numhask/issues-author:             Tony Day-maintainer:         tonyday567@gmail.com-copyright:          Tony Day-license:            BSD-3-Clause-license-file:       LICENSE-build-type:         Simple+build-type: Simple tested-with:-  GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.5 || ==9.6.2--extra-doc-files:    other/*.svg,-                    ChangeLog.md+    GHC ==8.6.5 || ==8.8.4 || ==8.10.7 || ==9.0.2 || ==9.2.8 || ==9.4.5 || ==9.6.2+extra-doc-files:+    ChangeLog.md+    other/*.svg  source-repository head-  type:     git-  location: https://github.com/tonyday567/numhask-  subdir:   numhask--common ghc2021-stanza-  if impl(ghc >=9.2)-    default-language:-      GHC2021-  if impl(ghc <9.2)-    default-language:-      Haskell2010-    default-extensions:-      BangPatterns-      BinaryLiterals-      ConstrainedClassMethods-      ConstraintKinds-      DeriveDataTypeable-      DeriveFoldable-      DeriveFunctor-      DeriveGeneric-      DeriveLift-      DeriveTraversable-      DoAndIfThenElse-      EmptyCase-      EmptyDataDecls-      EmptyDataDeriving-      ExistentialQuantification-      ExplicitForAll-      FlexibleContexts-      FlexibleInstances-      ForeignFunctionInterface-      GADTSyntax-      GeneralisedNewtypeDeriving-      HexFloatLiterals-      ImplicitPrelude-      InstanceSigs-      KindSignatures-      MonomorphismRestriction-      MultiParamTypeClasses-      NamedFieldPuns-      NamedWildCards-      NumericUnderscores-      PatternGuards-      PolyKinds-      PostfixOperators-      RankNTypes-      RelaxedPolyRec-      ScopedTypeVariables-      StandaloneDeriving-      StarIsType-      TraditionalRecordSyntax-      TupleSections-      TypeApplications-      TypeOperators-      TypeSynonymInstances-  if impl(ghc <9.2) && impl(ghc >=8.10)-    default-extensions:-      ImportQualifiedPost-      StandaloneKindSignatures+    type: git+    location: https://github.com/tonyday567/numhask  common ghc-options-stanza-  ghc-options:-    -Wall-    -Wcompat-    -Wincomplete-record-updates-    -Wincomplete-uni-patterns-    -Wredundant-constraints-    -Widentities-    -Wpartial-fields-  if impl(ghc >=8.8)     ghc-options:-      -fwrite-ide-info-      -hiedir=.hie+        -Wall+        -Wcompat+        -Widentities+        -Wincomplete-record-updates+        -Wincomplete-uni-patterns+        -Wpartial-fields+        -Wredundant-constraints -library-  import: ghc2021-stanza-  import: ghc-options-stanza-  hs-source-dirs: src-  default-extensions:-    RebindableSyntax-  -- keeping ormolu happy-  if impl(ghc >=8.10)-    default-extensions:-      NoImportQualifiedPost-  build-depends:-    base >=4.7 && <5,-    -- keeping cabal-docspec happy-    QuickCheck >=2.14 && <3-  exposed-modules:-    NumHask-    NumHask.Algebra.Additive-    NumHask.Algebra.Field-    NumHask.Algebra.Group-    NumHask.Algebra.Lattice-    NumHask.Algebra.Metric-    NumHask.Algebra.Action-    NumHask.Algebra.Multiplicative-    NumHask.Algebra.Ring-    NumHask.Data.Complex-    NumHask.Data.Integral-    NumHask.Data.Rational-    NumHask.Exception-    NumHask.Prelude+    if impl ( ghc >= 8.8 )+        ghc-options:+            -fwrite-ide-info+            -hiedir=.hie -  other-modules:+common ghc2021-stanza+    if impl ( ghc >= 9.2 )+        default-language: GHC2021 +    if impl ( ghc < 9.2 )+        default-language: Haskell2010+        default-extensions:+            BangPatterns+            BinaryLiterals+            ConstrainedClassMethods+            ConstraintKinds+            DeriveDataTypeable+            DeriveFoldable+            DeriveFunctor+            DeriveGeneric+            DeriveLift+            DeriveTraversable+            DoAndIfThenElse+            EmptyCase+            EmptyDataDecls+            EmptyDataDeriving+            ExistentialQuantification+            ExplicitForAll+            FlexibleContexts+            FlexibleInstances+            ForeignFunctionInterface+            GADTSyntax+            GeneralisedNewtypeDeriving+            HexFloatLiterals+            ImplicitPrelude+            InstanceSigs+            KindSignatures+            MonomorphismRestriction+            MultiParamTypeClasses+            NamedFieldPuns+            NamedWildCards+            NumericUnderscores+            PatternGuards+            PolyKinds+            PostfixOperators+            RankNTypes+            RelaxedPolyRec+            ScopedTypeVariables+            StandaloneDeriving+            StarIsType+            TraditionalRecordSyntax+            TupleSections+            TypeApplications+            TypeOperators+            TypeSynonymInstances++    if impl ( ghc < 9.2 ) && impl ( ghc >= 8.10 )+        default-extensions:+            ImportQualifiedPost+            StandaloneKindSignatures++library+    import: ghc-options-stanza+    import: ghc2021-stanza+    hs-source-dirs: src+    build-depends:+        -- keeping cabal-docspec happy+        , QuickCheck >=2.14 && <3+        , base       >=4.7 && <5+    exposed-modules:+        NumHask+        NumHask.Algebra.Action+        NumHask.Algebra.Additive+        NumHask.Algebra.Field+        NumHask.Algebra.Group+        NumHask.Algebra.Lattice+        NumHask.Algebra.Metric+        NumHask.Algebra.Multiplicative+        NumHask.Algebra.Ring+        NumHask.Data.Complex+        NumHask.Data.Integral+        NumHask.Data.Rational+        NumHask.Exception+        NumHask.Prelude+    other-modules:+    default-extensions: RebindableSyntax++    -- keeping ormolu happy+    if impl ( ghc >= 8.10 )+        default-extensions: NoImportQualifiedPost
src/NumHask.hs view
@@ -266,7 +266,8 @@ -- numhask is largely a set of classes that can replace the 'GHC.Num.Num' class and it's descendents. -- Principles that have guided design include: ----- - __/balanced class density/__. The numeric heirarchy begins with addition and multiplication rather than from a Monoidal or Magma base. Whilst not being as principled as other approaches, this circumvents the instance explosion problems of Haskell whilst maintaining clarity of class purpose.+-- - __/balanced class density/__. The numeric hierarchy begins with addition and multiplication,+--   choosing not to build from a Magma base. Whilst not being as principled as other approaches, this circumvents the instance explosion problems of Haskell whilst maintaining clarity of class purpose. -- -- - __/operator-first/__. In all cases, a class exists to define useful operators. --   Major class groupings, such as 'Distributive', 'Ring' and 'Field' are type synonyms.@@ -290,7 +291,7 @@  -- $mapping ----- 'GHC.Num' is a very old part of haskell, and is virtually unchanged since it's specification in+-- 'GHC.Num' is a very old part of haskell, and is virtually unchanged since its specification in -- [haskell98](https://www.haskell.org/onlinereport/standard-prelude.html). -- -- A deconstruction of 'GHC.Num.Num' and mapping to numhask.@@ -309,7 +310,7 @@ -- -- '(*)' is an operator of the 'Multiplicative' class. ----- 'zero' and 'one' are also introduced to the numeric heirarchy.+-- 'zero' and 'one' are also introduced to the numeric hierarchy. -- -- >    -- | Absolute value. -- >    abs                 :: a -> a
src/NumHask/Algebra/Additive.hs view
@@ -1,18 +1,19 @@ -- | Additive classes module NumHask.Algebra.Additive   ( Additive (..),+    Sum (..),     sum,     accsum,     Subtractive (..),   ) where -import Data.Foldable (foldl') import Data.Int (Int16, Int32, Int64, Int8)+import Data.Semigroup (Semigroup (..)) import Data.Traversable (mapAccumL) import Data.Word (Word, Word16, Word32, Word64, Word8) import GHC.Natural (Natural (..))-import Prelude (Bool, Double, Float, Int, Integer, fromInteger)+import Prelude (Bool, Double, Eq, Float, Int, Integer, Ord, Show, fromInteger) import qualified Prelude as P  -- $setup@@ -42,12 +43,26 @@    zero :: a +-- | A wrapper for an Additive which distinguishes the additive structure+newtype Sum a = Sum+  { getSum :: a+  }+  deriving (Eq, Ord, Show)++instance (Additive a) => P.Semigroup (Sum a) where+  Sum a <> Sum b = Sum (a + b)++instance (Additive a) => P.Monoid (Sum a) where+  mempty = Sum zero++deriving instance (Additive a) => Additive (Sum a)+ -- | Compute the sum of a 'Data.Foldable.Foldable'. -- -- >>> sum [0..10] -- 55 sum :: (Additive a, P.Foldable f) => f a -> a-sum = foldl' (+) zero+sum = getSum P.. P.foldMap Sum  -- | Compute the accumulating sum of a 'Data.Traversable.Traversable'. --
src/NumHask/Algebra/Multiplicative.hs view
@@ -1,6 +1,7 @@ -- | Multiplicative classes module NumHask.Algebra.Multiplicative   ( Multiplicative (..),+    Product (..),     product,     accproduct,     Divisive (..),@@ -11,7 +12,7 @@ import Data.Traversable (mapAccumL) import Data.Word (Word, Word16, Word32, Word64, Word8) import GHC.Natural (Natural (..))-import Prelude (Double, Float, Int, Integer, fromInteger, fromRational)+import Prelude (Double, Eq, Float, Int, Integer, Ord, Show, fromInteger, fromRational) import qualified Prelude as P  -- $setup@@ -41,12 +42,24 @@    one :: a +-- | A wrapper for an Multiplicative which distinguishes the multiplicative structure+newtype Product a = Product+  { getProduct :: a+  }+  deriving (Eq, Ord, Show)++instance (Multiplicative a) => P.Semigroup (Product a) where+  Product a <> Product b = Product (a * b)++instance (Multiplicative a) => P.Monoid (Product a) where+  mempty = Product one+ -- | Compute the product of a 'Data.Foldable.Foldable'. -- -- >>> product [1..5] -- 120 product :: (Multiplicative a, P.Foldable f) => f a -> a-product = P.foldr (*) one+product = getProduct P.. P.foldMap Product  -- | Compute the accumulating product of a 'Data.Traversable.Traversable'. --
src/NumHask/Prelude.hs view
@@ -57,7 +57,7 @@ import Data.Function hiding (id, (.)) import Data.Kind import Data.Maybe-import Data.Semigroup+import Data.Semigroup hiding (Product (..), Sum (..)) import Data.Traversable import GHC.Exts import GHC.Generics