packages feed

numhask 0.12.1.0 → 0.13.0.0

raw patch · 12 files changed

+276/−140 lines, 12 filesdep ~QuickCheckdep ~doctest-parallel

Dependency ranges changed: QuickCheck, doctest-parallel

Files

ChangeLog.md view
@@ -1,3 +1,12 @@+0.13+===++- added modF, divF and divModF as field versions of modulo and diviso Integral functions.+- fixed bug in EuclideanPair log function.+- BoundedJoinSemiLattice becomes LowerBounded+- BoundedMeetSemiLattice becomes UpperBounded+- switch to GHC2024+ 0.12.1 === 
numhask.cabal view
@@ -1,6 +1,6 @@ cabal-version: 3.0 name: numhask-version: 0.12.1.0+version: 0.13.0.0 license: BSD-3-Clause license-file: LICENSE copyright: Tony Day (c) 2016@@ -11,79 +11,156 @@ 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/nh12.svg)+  ![nh](docs/other/nh12.svg) -    == Usage+  == Usage -    >>> {-# LANGUAGE GHC2021 #-}-    >>> {-# LANGUAGE RebindableSyntax #-}-    >>> import NumHask.Prelude+  >>> {-# LANGUAGE GHC2024 #-}+  >>> {-# LANGUAGE RebindableSyntax #-}+  >>> import NumHask.Prelude -    See "NumHask" for a detailed overview.+  See "NumHask" for a detailed overview.  build-type: Simple tested-with:-    , GHC == 9.10.1-    , GHC == 9.6.5-    , GHC == 9.8.2+  ghc ==9.6.7+  ghc ==9.8.4+  ghc ==9.10.2+  ghc ==9.12.2+ extra-doc-files:-    ChangeLog.md-    other/*.svg-    readme.md+  ChangeLog.md+  other/*.svg+  readme.md  source-repository head-    type: git-    location: https://github.com/tonyday567/numhask+  type: git+  location: https://github.com/tonyday567/numhask  common ghc-options-stanza-    ghc-options:-        -Wall-        -Wcompat-        -Widentities-        -Wincomplete-record-updates-        -Wincomplete-uni-patterns-        -Wpartial-fields-        -Wredundant-constraints+  ghc-options:+    -Wall+    -Wcompat+    -Widentities+    -Wincomplete-record-updates+    -Wincomplete-uni-patterns+    -Wpartial-fields+    -Wredundant-constraints -common ghc2021-stanza-    default-language: GHC2021+common ghc2021-additions+  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++common ghc2024-additions+  default-extensions:+    DataKinds+    DerivingStrategies+    DisambiguateRecordFields+    ExplicitNamespaces+    GADTs+    LambdaCase+    MonoLocalBinds+    RoleAnnotations++common ghc2024-stanza+  if impl(ghc >=9.10)+    default-language:+      GHC2024+  elif impl(ghc >=9.2)+    import: ghc2024-additions+    default-language:+      GHC2021+  else+    import: ghc2021-additions+    import: ghc2024-additions+    default-language:+      Haskell2010+ library-    import: ghc-options-stanza-    import: ghc2021-stanza-    hs-source-dirs: src-    build-depends: , base >=4.14 && <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.Positive-        NumHask.Data.Rational-        NumHask.Data.Wrapped-        NumHask.Exception-        NumHask.Prelude-    default-extensions: RebindableSyntax+  import: ghc-options-stanza+  import: ghc2024-stanza+  hs-source-dirs: src+  build-depends: base >=4.14 && <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.Positive+    NumHask.Data.Rational+    NumHask.Data.Wrapped+    NumHask.Exception+    NumHask.Prelude +  default-extensions: RebindableSyntax+ test-suite doctests-    import: ghc2021-stanza-    main-is: doctests.hs-    hs-source-dirs: test-    build-depends:-        , QuickCheck       >=2.14 && <2.16-        , base             >=4.14 && <5-        , doctest-parallel >=0.3 && <0.4-    default-extensions: RebindableSyntax-    ghc-options: -threaded-    type: exitcode-stdio-1.0+  import: ghc2024-stanza+  main-is: doctests.hs+  hs-source-dirs: test+  build-depends:+    QuickCheck >=2.14 && <2.17,+    base >=4.14 && <5,+    doctest-parallel >=0.3 && <0.5,++  default-extensions: RebindableSyntax+  ghc-options: -threaded+  type: exitcode-stdio-1.0
readme.md view
@@ -2,7 +2,7 @@ ===  [![Hackage](https://img.shields.io/hackage/v/numhask.svg)](https://hackage.haskell.org/package/numhask)-[![Build Status](https://github.com/tonyday567/numhask/workflows/haskell-ci/badge.svg)](https://github.com/tonyday567/numhask/actions?query=workflow%3Ahaskell-ci)+[![build](https://github.com/tonyday567/numhask/actions/workflows/haskell-ci.yml/badge.svg)](https://github.com/tonyday567/numhask/actions/workflows/haskell-ci.yml)  ![](other/nh12.svg) @@ -145,7 +145,7 @@       DivisiveAction,       JoinSemiLattice,       MeetSemiLattice,-      BoundedMeetSemiLattice+      UpperBounded     )     via (Wrapped a) ```
src/NumHask.hs view
@@ -45,6 +45,9 @@     negInfinity,     nan,     half,+    modF,+    divF,+    divModF,      -- * Lattice     JoinSemiLattice (..),@@ -53,8 +56,8 @@     MeetSemiLattice (..),     meetLeq,     (</),-    BoundedJoinSemiLattice (..),-    BoundedMeetSemiLattice (..),+    LowerBounded (..),+    UpperBounded (..),      -- * Action     AdditiveAction (..),@@ -139,16 +142,19 @@     Field,     QuotientField (..),     TrigField (..),+    divF,+    divModF,     half,     infinity,+    modF,     nan,     negInfinity,   ) import NumHask.Algebra.Lattice-  ( BoundedJoinSemiLattice (..),-    BoundedMeetSemiLattice (..),-    JoinSemiLattice (..),+  ( JoinSemiLattice (..),+    LowerBounded (..),     MeetSemiLattice (..),+    UpperBounded (..),     joinLeq,     meetLeq,     (</),
src/NumHask/Algebra/Field.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE TypeFamilies #-} --- | Field classes+-- | [field](https://en.wikipedia.org/wiki/Field_(mathematics\)) classes module NumHask.Algebra.Field   ( SemiField,     Field,@@ -12,6 +12,9 @@     nan,     TrigField (..),     half,+    modF,+    divF,+    divModF,   ) where @@ -24,8 +27,8 @@     (/),   ) import NumHask.Algebra.Ring (Distributive, Ring, two)-import NumHask.Data.Integral (Integral, even)-import Prelude ((.))+import NumHask.Data.Integral (FromIntegral (..), Integral, even)+import Prelude (Eq (..), (.)) import Prelude qualified as P  -- $setup@@ -35,7 +38,7 @@ -- >>> :set -XScopedTypeVariables -- >>> import NumHask.Prelude --- | A <https://en.wikipedia.org/wiki/Semifield Semifield> is a field with no substraction.+-- | A <https://en.wikipedia.org/wiki/Semifield Semifield> is a field with no subtraction. -- -- @since 0.12 type SemiField a = (Distributive a, Divisive a)@@ -277,3 +280,43 @@ -- 0.5 half :: (Additive a, Divisive a) => a half = one / two++-- | Approximate modulo for fields+--+-- @since 0.13+--+-- >>> modF 1.5 1.2+-- 0.30000000000000004+modF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> a+modF n d+  | d == infinity = n+  | d == zero = nan+  | P.True = n - d * fromIntegral (floor (n / d))++-- | Approximate diviso for fields.+--+-- Compared with 'NumHask.Algebra.Field.div', divF returns the original type rather than the 'Whole' type.+--+-- @since 0.13+--+-- >>> divF 1.5 1.2+-- 1.0+divF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> a+divF n d+  | d == infinity = zero+  | d == zero = infinity+  | P.True = fromIntegral (floor (n / d))++-- | Approximate `NumHask.Algebra.Field.divMod` for fields.+--+-- @since 0.13+--+-- >>> divModF 1.5 1.2+-- (1.0,0.30000000000000004)+divModF :: (Eq a, Field a, FromIntegral a (Whole a), QuotientField a) => a -> a -> (a, a)+divModF n d+  | d == infinity = (zero, n)+  | d == zero = (infinity, nan)+  | P.True = (div', n - d * div')+  where+    div' = fromIntegral (floor (n / d))
src/NumHask/Algebra/Lattice.hs view
@@ -6,8 +6,8 @@     MeetSemiLattice (..),     meetLeq,     (</),-    BoundedJoinSemiLattice (..),-    BoundedMeetSemiLattice (..),+    LowerBounded (..),+    UpperBounded (..),     Lattice,     BoundedLattice,   )@@ -77,20 +77,20 @@ -- | A join-semilattice with an identity element 'bottom' for '\/'. -- -- > x \/ bottom == bottom-class (JoinSemiLattice a) => BoundedJoinSemiLattice a where+class (JoinSemiLattice a) => LowerBounded a where   bottom :: a  -- | A meet-semilattice with an identity element 'top' for '/\'. -- -- > x /\ top == top-class (MeetSemiLattice a) => BoundedMeetSemiLattice a where+class (MeetSemiLattice a) => UpperBounded a where   top :: a  -- | Lattices with both bounds -- -- > x /\ bottom == x -- > x \/ top = x-type BoundedLattice a = (JoinSemiLattice a, MeetSemiLattice a, BoundedJoinSemiLattice a, BoundedMeetSemiLattice a)+type BoundedLattice a = (JoinSemiLattice a, MeetSemiLattice a, LowerBounded a, UpperBounded a)  instance JoinSemiLattice Float where   (\/) = min@@ -182,83 +182,83 @@ instance MeetSemiLattice Word64 where   (/\) = max -instance BoundedJoinSemiLattice Float where+instance LowerBounded Float where   bottom = negInfinity -instance BoundedMeetSemiLattice Float where+instance UpperBounded Float where   top = infinity -instance BoundedJoinSemiLattice Double where+instance LowerBounded Double where   bottom = negInfinity -instance BoundedMeetSemiLattice Double where+instance UpperBounded Double where   top = infinity -instance BoundedJoinSemiLattice Int where+instance LowerBounded Int where   bottom = minBound -instance BoundedMeetSemiLattice Int where+instance UpperBounded Int where   top = maxBound -instance BoundedJoinSemiLattice Bool where+instance LowerBounded Bool where   bottom = False -instance BoundedMeetSemiLattice Bool where+instance UpperBounded Bool where   top = True -instance BoundedJoinSemiLattice Natural where+instance LowerBounded Natural where   bottom = zero -instance BoundedJoinSemiLattice Int8 where+instance LowerBounded Int8 where   bottom = minBound -instance BoundedMeetSemiLattice Int8 where+instance UpperBounded Int8 where   top = maxBound -instance BoundedJoinSemiLattice Int16 where+instance LowerBounded Int16 where   bottom = minBound -instance BoundedMeetSemiLattice Int16 where+instance UpperBounded Int16 where   top = maxBound -instance BoundedJoinSemiLattice Int32 where+instance LowerBounded Int32 where   bottom = minBound -instance BoundedMeetSemiLattice Int32 where+instance UpperBounded Int32 where   top = maxBound -instance BoundedJoinSemiLattice Int64 where+instance LowerBounded Int64 where   bottom = minBound -instance BoundedMeetSemiLattice Int64 where+instance UpperBounded Int64 where   top = maxBound -instance BoundedJoinSemiLattice Word where+instance LowerBounded Word where   bottom = minBound -instance BoundedMeetSemiLattice Word where+instance UpperBounded Word where   top = maxBound -instance BoundedJoinSemiLattice Word8 where+instance LowerBounded Word8 where   bottom = minBound -instance BoundedMeetSemiLattice Word8 where+instance UpperBounded Word8 where   top = maxBound -instance BoundedJoinSemiLattice Word16 where+instance LowerBounded Word16 where   bottom = minBound -instance BoundedMeetSemiLattice Word16 where+instance UpperBounded Word16 where   top = maxBound -instance BoundedJoinSemiLattice Word32 where+instance LowerBounded Word32 where   bottom = minBound -instance BoundedMeetSemiLattice Word32 where+instance UpperBounded Word32 where   top = maxBound -instance BoundedJoinSemiLattice Word64 where+instance LowerBounded Word64 where   bottom = minBound -instance BoundedMeetSemiLattice Word64 where+instance UpperBounded Word64 where   top = maxBound
src/NumHask/Algebra/Metric.hs view
@@ -2,8 +2,6 @@ {-# LANGUAGE DerivingVia #-} {-# LANGUAGE TypeFamilies #-} {-# LANGUAGE UndecidableInstances #-}-{-# OPTIONS_GHC -Wno-name-shadowing #-}-{-# OPTIONS_GHC -Wno-type-equality-out-of-scope #-}  -- | Metric classes module NumHask.Algebra.Metric@@ -30,6 +28,7 @@ import Data.Bool import Data.Int (Int16, Int32, Int64, Int8) import Data.Kind+import Data.Type.Equality import Data.Word (Word16, Word32, Word64, Word8) import GHC.Generics import GHC.Natural (Natural (..))@@ -39,7 +38,7 @@ import NumHask.Algebra.Lattice import NumHask.Algebra.Multiplicative import NumHask.Algebra.Ring-import Prelude (Double, Eq (..), Float, Functor (..), Int, Integer, Ord, Show, Word, fromRational)+import Prelude (Double, Eq (..), Float, Functor (..), Int, Integer, Ord (..), Show, Word, fromRational) import Prelude qualified as P  -- $setup@@ -372,10 +371,10 @@ instance (MeetSemiLattice a) => MeetSemiLattice (EuclideanPair a) where   (/\) (EuclideanPair (x, y)) (EuclideanPair (x', y')) = EuclideanPair (x /\ x', y /\ y') -instance (BoundedJoinSemiLattice a) => BoundedJoinSemiLattice (EuclideanPair a) where+instance (LowerBounded a) => LowerBounded (EuclideanPair a) where   bottom = pure bottom -instance (BoundedMeetSemiLattice a) => BoundedMeetSemiLattice (EuclideanPair a) where+instance (UpperBounded a) => UpperBounded (EuclideanPair a) where   top = pure top  instance (Multiplicative a) => MultiplicativeAction (EuclideanPair a) where@@ -387,17 +386,7 @@  instance (Ord a, TrigField a, ExpField a) => ExpField (EuclideanPair a) where   exp (EuclideanPair (x, y)) = EuclideanPair (exp x * cos y, exp x * sin y)-  log (EuclideanPair (x, y)) = EuclideanPair (log (sqrt (x * x + y * y)), atan2' y x)-    where-      atan2' y x-        | x P.> zero = atan (y / x)-        | x P.== zero P.&& y P.> zero = pi / (one + one)-        | x P.< one P.&& y P.> one = pi + atan (y / x)-        | (x P.<= zero P.&& y P.< zero) || (x P.< zero) =-            negate (atan2' (negate y) x)-        | y P.== zero = pi -- must be after the previous test on zero y-        | x P.== zero P.&& y P.== zero = y -- must be after the other double zero tests-        | P.otherwise = x + y -- x or y is a NaN, return a NaN (via +)+  log (EuclideanPair (x, y)) = EuclideanPair (log (sqrt (x * x + y * y)), atan2 y x)  instance (QuotientField a, Subtractive a) => QuotientField (EuclideanPair a) where   type Whole (EuclideanPair a) = EuclideanPair (Whole a)
src/NumHask/Data/Complex.hs view
@@ -41,6 +41,11 @@     (/),   ) +-- $setup+--+-- >>> import NumHask.Prelude+-- >>> :m -Prelude+ -- | The underlying representation is a newtype-wrapped tuple, compared with the base datatype. This was chosen to facilitate the use of DerivingVia. newtype Complex a = Complex {complexPair :: (a, a)}   deriving stock@@ -59,8 +64,8 @@       Epsilon,       JoinSemiLattice,       MeetSemiLattice,-      BoundedJoinSemiLattice,-      BoundedMeetSemiLattice,+      LowerBounded,+      UpperBounded,       ExpField     )     via (EuclideanPair a)@@ -68,6 +73,14 @@ infixl 6 +:  -- | Complex number constructor.+--+-- Internally, Complex derives most instances via EuclideanPair. For instance,+--+-- >>> sqrt (1.0 +: (-1.0)) :: Complex Double+-- Complex {complexPair = (1.0986841134678098,-0.45508986056222733)}+--+-- >>> sqrt ((-1.0) +: 0.0) :: Complex Double+-- Complex {complexPair = (6.123233995736766e-17,1.0)} (+:) :: a -> a -> Complex a (+:) r i = Complex (r, i) 
src/NumHask/Data/Integral.hs view
@@ -116,6 +116,18 @@   rem f f' a = f a `mod` f' a   quotRem f f' = (\a -> fst (f a `quotRem` f' a), \a -> snd (f a `quotRem` f' a)) +-- |+-- >>> even 2+-- True+even :: (P.Eq a, Integral a) => a -> P.Bool+even n = n `rem` (one + one) P.== zero++-- |+-- >>> odd 3+-- True+odd :: (P.Eq a, Integral a) => a -> P.Bool+odd = P.not . even+ -- | toIntegral is kept separate from Integral to help with compatability issues. -- -- > toIntegral a == a@@ -408,18 +420,6 @@  instance FromInteger Word64 where   fromInteger = P.fromInteger---- |--- >>> even 2--- True-even :: (P.Eq a, Integral a) => a -> P.Bool-even n = n `rem` (one + one) P.== zero---- |--- >>> odd 3--- True-odd :: (P.Eq a, Integral a) => a -> P.Bool-odd = P.not . even  infixr 8 ^^ 
src/NumHask/Data/Positive.hs view
@@ -84,7 +84,7 @@       DivisiveAction,       JoinSemiLattice,       MeetSemiLattice,-      BoundedMeetSemiLattice+      UpperBounded     )     via (Wrapped a) @@ -103,7 +103,7 @@ instance (ToRatio a b) => ToRatio (Positive a) b where   toRatio (UnsafePositive a) = toRatio a -instance (Additive a, JoinSemiLattice a) => BoundedJoinSemiLattice (Positive a) where+instance (Additive a, JoinSemiLattice a) => LowerBounded (Positive a) where   bottom = UnsafePositive zero  instance QuotientField (Positive P.Double) where@@ -161,7 +161,7 @@    infixl 6 ∸   (∸) :: a -> a -> a-  default (∸) :: (BoundedJoinSemiLattice a, MeetSemiLattice a, Subtractive a) => a -> a -> a+  default (∸) :: (LowerBounded a, MeetSemiLattice a, Subtractive a) => a -> a -> a   a ∸ b = bottom /\ (a - b)  -- | Truncated addition@@ -171,5 +171,5 @@   {-# MINIMAL (∔) #-}   infixl 6 ∔   (∔) :: a -> a -> a-  default (∔) :: (BoundedMeetSemiLattice a, JoinSemiLattice a, Additive a) => a -> a -> a+  default (∔) :: (UpperBounded a, JoinSemiLattice a, Additive a) => a -> a -> a   a ∔ b = top \/ (a + b)
src/NumHask/Data/Wrapped.hs view
@@ -37,8 +37,8 @@       FromRational,       MeetSemiLattice,       JoinSemiLattice,-      BoundedJoinSemiLattice,-      BoundedMeetSemiLattice,+      LowerBounded,+      UpperBounded,       Basis,       Direction,       Epsilon,
src/NumHask/Exception.hs view
@@ -6,11 +6,10 @@ where  import Control.Exception-import Data.Typeable (Typeable) import Prelude qualified as P  -- | A numhask exception. newtype NumHaskException = NumHaskException {errorMessage :: P.String}-  deriving (P.Show, Typeable)+  deriving (P.Show)  instance Exception NumHaskException