packages feed

numhask-prelude 0.1.0.1 → 0.5.0

raw patch · 6 files changed

Files

numhask-prelude.cabal view
@@ -1,54 +1,71 @@-name:           numhask-prelude-version:        0.1.0.1-synopsis:       A numeric prelude-description:    A numeric prelude, combining protolude and numhask.-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:        BSD3-license-file:   LICENSE-build-type:     Simple-cabal-version:  >= 1.18--extra-source-files:-    stack.yaml-+cabal-version: 3.0+name: numhask-prelude+version: 0.5.0+synopsis:+  A numeric prelude+description:+  A numeric prelude, combining protolude and numhask.+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 source-repository head-  type: git-  location: https://github.com/tonyday567/numhask-+  type:+    git+  location:+    https://github.com/tonyday567/numhask+  subdir:+    numhask-prelude library   hs-source-dirs:-      src-  default-extensions: NegativeLiterals NoImplicitPrelude OverloadedStrings UnicodeSyntax+    src+  default-extensions:+    NegativeLiterals+    NoImplicitPrelude+    OverloadedStrings+    UnicodeSyntax   ghc-options:-      -Wall-      -Wcompat-      -Wincomplete-record-updates-      -Wincomplete-uni-patterns-      -Wredundant-constraints+    -Wall+    -Wcompat+    -Wincomplete-record-updates+    -Wincomplete-uni-patterns+    -Wredundant-constraints   build-depends:-      base >=4.7 && <4.12-    , numhask >=0.2.3.0 && <0.3-    , protolude >=0.1 && <0.3+      base >=4.7 && <5+    , numhask >=0.3 && <0.6+    , protolude >=0.3 && <0.4   exposed-modules:-      NumHask.Prelude-      NumHask.Error-      NumHask.Examples-  other-modules:-      Paths_numhask_prelude+    NumHask.Prelude+    NumHask.Error+    NumHask.Examples   default-language: Haskell2010- test-suite test-  type: exitcode-stdio-1.0-  main-is: test.hs+  type:+    exitcode-stdio-1.0+  main-is:+    test.hs   hs-source-dirs:-      test-  default-extensions: NegativeLiterals NoImplicitPrelude OverloadedStrings UnicodeSyntax+    test+  default-extensions:+    NegativeLiterals+    NoImplicitPrelude+    OverloadedStrings+    UnicodeSyntax   build-depends:-      doctest+      doctest >=0.13 && <0.17     , numhask-prelude   default-language: Haskell2010
src/NumHask/Error.hs view
@@ -3,7 +3,6 @@ module NumHask.Error where  import Protolude-import Protolude.Panic (panic)  impossible :: HasCallStack => Text -> a impossible = panic
src/NumHask/Examples.hs view
@@ -1,8 +1,10 @@ {-# LANGUAGE DataKinds #-}-{-# LANGUAGE GeneralizedNewtypeDeriving #-}+{-# LANGUAGE FlexibleContexts #-}+{-# LANGUAGE FlexibleInstances #-}+{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NoImplicitPrelude #-}-{-# LANGUAGE RebindableSyntax #-} {-# LANGUAGE OverloadedLists #-}+{-# LANGUAGE RebindableSyntax #-} {-# OPTIONS_GHC -Wall #-} {-# OPTIONS_GHC -fno-warn-unused-imports #-} @@ -24,7 +26,8 @@      -- ** Matrices     -- $matrices-  ) where+  )+where  import NumHask.Prelude @@ -33,6 +36,8 @@ -- -- $setup -- >>> :set -XNoImplicitPrelude+-- >>> :set -XFlexibleContexts+-- >>> :set -XRebindableSyntax -- >>> import NumHask.Prelude -- -- $basic@@ -44,21 +49,23 @@ -- 0 -- >>> 1 * 1 -- 1--- >>> 1 / 1+--+-- >>> 1.0 / 1.0 -- 1.0 -- -- Note that the literal numbers in the divide above defaulted to Float rather than Int. -- -- >>> 1 / (1::Int) -- ...--- ... No instance for (MultiplicativeGroup Int)+-- ... No instance for (Divisive Int) ... -- ... ----- >>> 1 / fromIntegral (1::Int)+-- >>> 1.0 / fromInteger 1 -- 1.0 ----- RebindableSyntax removes the Haskell98 link between literal numbers and base classes.  Literal numbers are pre-processed by ghc as `fromInteger 1` and `fromRational 1.0`.+-- RebindableSyntax removes the Haskell98 link between literal numbers and prelude.  Literal numbers are pre-pended by ghc with `fromInteger` for integers and `fromRational` for decimals. --+-- >>> :set -XNoRebindableSyntax -- >>> :t 1 -- 1 :: Num p => p --@@ -70,7 +77,7 @@ -- 1 :: FromInteger a => a -- -- >>> :t 1.0--- 1.0 :: FromRatio b => b+-- 1.0 :: FromRational a => a -- -- 'Float' and 'Double' are 'NumHask.Algebra.Fields.Field' instances. --@@ -96,10 +103,19 @@ -- -- 'BoundedField' --+-- >>> 1.0/0.0+-- Infinity+-- >>> -1.0/0.0+-- -Infinity+-- >>> 0.0/0.0 + 1.0+-- NaN+-- -- >>> one/zero -- Infinity+-- -- >>> -one/zero -- -Infinity+-- -- >>> zero/zero+one -- NaN --@@ -125,17 +141,6 @@ -- (-1) :+ (-2) -- >>> (1 :+ (-2)) * ((-2) :+ 4) -- 6 :+ 8--- >>> (1 :+ (-1)) / (2 :+ 2)+--+-- >>> (1.0 :+ (-1.0)) / (2.0 :+ 2.0) -- 0.0 :+ (-0.5)--newtype PositiveFloat = PositiveFloat { unPositive :: Float } deriving (Show, Eq, AdditiveMagma, AdditiveAssociative, AdditiveUnital, AdditiveCommutative, Additive, MultiplicativeMagma, MultiplicativeUnital, MultiplicativeAssociative, MultiplicativeCommutative, Multiplicative, MultiplicativeInvertible, MultiplicativeGroup, Distribution, Semiring, Ring, CRing, Semifield, UpperBoundedField)--instance AdditiveInvertible PositiveFloat where-  negate _ = nan--instance AdditiveGroup PositiveFloat--instance Bounded PositiveFloat where-  minBound = zero-  maxBound = infinity-
src/NumHask/Prelude.hs view
@@ -1,80 +1,79 @@-{-# LANGUAGE CPP #-} {-# OPTIONS_GHC -Wall #-}+{-# OPTIONS_HADDOCK prune #-} --- | A prelude for NumHask+-- | Combines 'Protolude' and 'numhask'. module NumHask.Prelude-  ( -- * Backend-    -- $backend-    module Protolude-#if !MIN_VERSION_base(4,11,0)-  , (<>)-  , Semigroup-#endif-    -- RebindableSyntax takes fromString and fail away so we need to put it back in-  , fromString-  , fail-  , Complex(..)-  , module NumHask.Data.LogField-  , Natural(..)-    -- * Algebraic Heirarchy+  ( -- * NumHask     -- $instances-  , module NumHask.Algebra.Additive-  , module NumHask.Algebra.Basis-  , module NumHask.Algebra.Distribution-  , module NumHask.Algebra.Field-  , module NumHask.Algebra.Integral-  , module NumHask.Algebra.Magma-  , module NumHask.Algebra.Metric-  , module NumHask.Algebra.Module-  , module NumHask.Algebra.Multiplicative-  , module NumHask.Algebra.Rational-  , module NumHask.Algebra.Ring-  , module NumHask.Algebra.Singleton -  ) where+    module NumHask.Algebra.Abstract.Action,+    module NumHask.Algebra.Abstract.Additive,+    module NumHask.Algebra.Abstract.Field,+    module NumHask.Algebra.Abstract.Group,+    module NumHask.Algebra.Abstract.Lattice,+    module NumHask.Algebra.Abstract.Module,+    module NumHask.Algebra.Abstract.Multiplicative,+    module NumHask.Algebra.Abstract.Ring,+    module NumHask.Algebra.Linear.Hadamard,+    module NumHask.Analysis.Metric,+    module NumHask.Data.Complex,+    module NumHask.Data.Integral,+    module NumHask.Data.LogField,+    module NumHask.Data.Rational,+    module NumHask.Data.Pair,+    module NumHask.Data.Positive,+    Natural (..),+    module NumHask.Exception, -#if MIN_VERSION_base(4,11,0)-import Protolude-       hiding (Integral(..), Rep, Semiring(..), (*), (**),-               (+), (-), (/), (^), (^^), abs, acos, acosh, asin, asinh, atan,-               atan2, atanh, ceiling, cos, cosh, exp, floor, fromInteger,-               fromIntegral, even, odd, infinity, log, logBase, negate, pi, product,-               properFraction, recip, round, sin, sinh, sqrt, sum, tan, tanh, toInteger, trans,-               zero, fromRational, Ratio(..), Rational, reduce, gcd, subtract)-#else-import Protolude-       hiding (Integral(..), Rep, Semiring(..), (*), (**),-               (+), (-), (/), (^), (^^), abs, acos, acosh, asin, asinh, atan,-               atan2, atanh, ceiling, cos, cosh, exp, floor, fromInteger,-               fromIntegral, even, odd, infinity, log, logBase, negate, pi, product,-               properFraction, recip, round, sin, sinh, sqrt, sum, tan, tanh, toInteger, trans,-               zero, fromRational, Ratio(..), Rational, reduce, gcd, subtract, (<>), Semigroup)-import Data.Semigroup ((<>), Semigroup)-#endif+    -- * Backend+    -- $backend +    id,+    module Protolude,+    -- | Using different types for numbers requires RebindableSyntax.  This then removes all sorts of base-level stuff that has to be put back in.+    fromString,+    fail,+    ifThenElse,+    fromList,+    fromListN,+  )+where+ import Control.Monad (fail) import Data.String-import GHC.Natural(Natural(..))--import NumHask.Algebra.Additive-import NumHask.Algebra.Basis-import NumHask.Algebra.Distribution-import NumHask.Algebra.Field-import NumHask.Algebra.Integral-import NumHask.Algebra.Magma-import NumHask.Algebra.Metric-import NumHask.Algebra.Module-import NumHask.Algebra.Multiplicative-import NumHask.Algebra.Rational-import NumHask.Algebra.Ring-import NumHask.Algebra.Singleton+import GHC.Exts+import GHC.Natural (Natural (..))+import NumHask.Algebra.Abstract.Action+import NumHask.Algebra.Abstract.Additive+import NumHask.Algebra.Abstract.Field+import NumHask.Algebra.Abstract.Group+import NumHask.Algebra.Abstract.Lattice+import NumHask.Algebra.Abstract.Module+import NumHask.Algebra.Abstract.Multiplicative+import NumHask.Algebra.Abstract.Ring+import NumHask.Algebra.Linear.Hadamard+import NumHask.Analysis.Metric+import NumHask.Data.Complex+import NumHask.Data.Integral import NumHask.Data.LogField+import NumHask.Data.Pair+import NumHask.Data.Positive+import NumHask.Data.Rational+import NumHask.Exception+import Protolude hiding ((*), (**), (+), (-), (/), Complex (..), Integral (..), Product (..), Ratio, Rep, Semiring (..), Sum (..), (^), (^^), abs, acos, acosh, asin, asinh, atan, atan2, atanh, ceiling, cis, cos, cosh, even, exp, floor, fromInteger, fromIntegral, fromRational, gcd, imagPart, infinity, log, logBase, magnitude, mkPolar, negate, odd, phase, pi, polar, product, properFraction, realPart, recip, reduce, round, sin, sinh, sqrt, subtract, sum, tan, tanh, toInteger, toRational, trans, truncate, zero)+import Control.Category (id)  -- $backend--- NumHask imports Protolude as the prelude and replaces much of the 'Num' heirarchy in base.--- Usage of 'Semigroup' and 'Monoid' has been avoided to retain basic compatability.+-- NumHask imports Protolude as a starting prelude.+--+-- In addition, 'id' is imported (protolude uses 'identity')+ -- $instances--- Re-defines the numeric tower.+-- NumHask replaces much of the 'Num' and 'Real' heirarchies in protolude & base. -- -- Instances for 'Int', 'Integer', 'Float', 'Double', 'Bool', 'Complex' and 'Natural'are supplied.---++-- | rebindable syntax splats this, and I'm not sure where it exists in GHC land+ifThenElse :: Bool -> a -> a -> a+ifThenElse True x _ = x+ifThenElse False _ y = y
− stack.yaml
@@ -1,8 +0,0 @@-resolver: nightly-2018-05-06--packages:-  - .-  # - ../numhask--extra-deps:-  - numhask-0.2.3.0
test/test.hs view
@@ -1,5 +1,3 @@-{-# LANGUAGE TypeSynonymInstances #-}-{-# LANGUAGE FlexibleInstances #-} {-# OPTIONS_GHC -Wall #-}  module Main where