packages feed

mixed-types-num 0.5.12 → 0.6.0

raw patch · 5 files changed

+48/−6 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Numeric.MixedTypes.Literals: fromIntegerWithSample :: HasIntegersWithSample t => t -> Integer -> t
+ Numeric.MixedTypes.Literals: fromRationalWithSample :: HasRationalsWithSample t => t -> Rational -> t
+ Numeric.MixedTypes.Literals: instance (Numeric.MixedTypes.Literals.HasIntegers t, GHC.Base.Monoid es) => Numeric.MixedTypes.Literals.ConvertibleExactly (Control.CollectErrors.Type.CollectErrors es t, GHC.Num.Integer.Integer) (Control.CollectErrors.Type.CollectErrors es t)
+ Numeric.MixedTypes.Literals: instance (Numeric.MixedTypes.Literals.HasRationals t, GHC.Base.Monoid es) => Numeric.MixedTypes.Literals.ConvertibleExactly (Control.CollectErrors.Type.CollectErrors es t, GHC.Real.Rational) (Control.CollectErrors.Type.CollectErrors es t)
+ Numeric.MixedTypes.Literals: instance Numeric.MixedTypes.Literals.ConvertibleExactly (GHC.Num.Integer.Integer, GHC.Num.Integer.Integer) GHC.Num.Integer.Integer
+ Numeric.MixedTypes.Literals: instance Numeric.MixedTypes.Literals.ConvertibleExactly (GHC.Real.Rational, GHC.Num.Integer.Integer) GHC.Real.Rational
+ Numeric.MixedTypes.Literals: instance Numeric.MixedTypes.Literals.ConvertibleExactly (GHC.Real.Rational, GHC.Real.Rational) GHC.Real.Rational
+ Numeric.MixedTypes.Literals: type HasIntegersWithSample t = ConvertibleExactly (t, Integer) t
+ Numeric.MixedTypes.Literals: type HasRationalsWithSample t = ConvertibleExactly (t, Rational) t
+ Numeric.MixedTypes.PreludeHiding: class a ~# b => (a :: k) ~ (b :: k)
+ Numeric.MixedTypes.PreludeHiding: liftA2 :: Applicative f => (a -> b -> c) -> f a -> f b -> f c
- Numeric.MixedTypes.Field: class (Ring t, HasRationals t, CanPowBy t Integer, CanPowBy t Int, CanDivSameType t, CanRecipSameType t, CanAddSubMulDivBy t Rational, CanAddSubMulDivBy t Integer, CanAddSubMulDivBy t Int) => Field t
+ Numeric.MixedTypes.Field: class (Ring t, HasRationalsWithSample t, CanPowBy t Integer, CanPowBy t Int, CanDivSameType t, CanRecipSameType t, CanAddSubMulDivBy t Rational, CanAddSubMulDivBy t Integer, CanAddSubMulDivBy t Int) => Field t
- Numeric.MixedTypes.PreludeHiding: class Bounded a
+ Numeric.MixedTypes.PreludeHiding: class () => Bounded a
- Numeric.MixedTypes.PreludeHiding: class Enum a
+ Numeric.MixedTypes.PreludeHiding: class () => Enum a
- Numeric.MixedTypes.PreludeHiding: class Foldable (t :: TYPE LiftedRep -> Type)
+ Numeric.MixedTypes.PreludeHiding: class () => Foldable (t :: Type -> Type)
- Numeric.MixedTypes.PreludeHiding: class Functor (f :: Type -> Type)
+ Numeric.MixedTypes.PreludeHiding: class () => Functor (f :: Type -> Type)
- Numeric.MixedTypes.PreludeHiding: class Read a
+ Numeric.MixedTypes.PreludeHiding: class () => Read a
- Numeric.MixedTypes.PreludeHiding: class Semigroup a
+ Numeric.MixedTypes.PreludeHiding: class () => Semigroup a
- Numeric.MixedTypes.PreludeHiding: class Show a
+ Numeric.MixedTypes.PreludeHiding: class () => Show a
- Numeric.MixedTypes.PreludeHiding: cycle :: [a] -> [a]
+ Numeric.MixedTypes.PreludeHiding: cycle :: HasCallStack => [a] -> [a]
- Numeric.MixedTypes.PreludeHiding: data Bool
+ Numeric.MixedTypes.PreludeHiding: data () => Bool
- Numeric.MixedTypes.PreludeHiding: data Char
+ Numeric.MixedTypes.PreludeHiding: data () => Char
- Numeric.MixedTypes.PreludeHiding: data Double
+ Numeric.MixedTypes.PreludeHiding: data () => Double
- Numeric.MixedTypes.PreludeHiding: data Either a b
+ Numeric.MixedTypes.PreludeHiding: data () => Either a b
- Numeric.MixedTypes.PreludeHiding: data Float
+ Numeric.MixedTypes.PreludeHiding: data () => Float
- Numeric.MixedTypes.PreludeHiding: data IO a
+ Numeric.MixedTypes.PreludeHiding: data () => IO a
- Numeric.MixedTypes.PreludeHiding: data Int
+ Numeric.MixedTypes.PreludeHiding: data () => Int
- Numeric.MixedTypes.PreludeHiding: data Integer
+ Numeric.MixedTypes.PreludeHiding: data () => Integer
- Numeric.MixedTypes.PreludeHiding: data Maybe a
+ Numeric.MixedTypes.PreludeHiding: data () => Maybe a
- Numeric.MixedTypes.PreludeHiding: data Ordering
+ Numeric.MixedTypes.PreludeHiding: data () => Ordering
- Numeric.MixedTypes.PreludeHiding: data Word
+ Numeric.MixedTypes.PreludeHiding: data () => Word
- Numeric.MixedTypes.PreludeHiding: head :: [a] -> a
+ Numeric.MixedTypes.PreludeHiding: head :: HasCallStack => [a] -> a
- Numeric.MixedTypes.PreludeHiding: init :: [a] -> [a]
+ Numeric.MixedTypes.PreludeHiding: init :: HasCallStack => [a] -> [a]
- Numeric.MixedTypes.PreludeHiding: last :: [a] -> a
+ Numeric.MixedTypes.PreludeHiding: last :: HasCallStack => [a] -> a
- Numeric.MixedTypes.PreludeHiding: tail :: [a] -> [a]
+ Numeric.MixedTypes.PreludeHiding: tail :: HasCallStack => [a] -> [a]
- Numeric.MixedTypes.Ring: class (CanNegSameType t, CanAddSameType t, CanSubSameType t, CanMulSameType t, HasEq t t, HasEq t Integer, CanAddSubMulBy t Integer, HasEq t Int, CanAddSubMulBy t Int, HasIntegers t) => Ring t
+ Numeric.MixedTypes.Ring: class (CanNegSameType t, CanAddSameType t, CanSubSameType t, CanMulSameType t, HasEq t t, HasEq t Integer, CanAddSubMulBy t Integer, HasEq t Int, CanAddSubMulBy t Int, HasIntegersWithSample t) => Ring t

Files

changelog.md view
@@ -1,5 +1,8 @@ # mixed-types-num change log +* v 0.6.0 2024-09-21+  * Ring now requires HasIntegersWithSample instead of HasIntegers+  * Field now requires HasRationalsWithSample instead of HasRationals * v 0.5.12 2023-08-14   * compatible with ghc 9.6.2   * remove dependency on mtl
mixed-types-num.cabal view
@@ -1,11 +1,11 @@ cabal-version: 1.12 --- This file has been generated from package.yaml by hpack version 0.35.2.+-- This file has been generated from package.yaml by hpack version 0.36.0. -- -- see: https://github.com/sol/hpack  name:           mixed-types-num-version:        0.5.12+version:        0.6.0 synopsis:       Alternative Prelude with numeric and logic expressions typed bottom-up description:    Please see the README on GitHub at <https://github.com/michalkonecny/mixed-types-num#readme> category:       Math
src/Numeric/MixedTypes/Field.hs view
@@ -43,7 +43,7 @@  class   (Ring t,-   HasRationals t,+   HasRationalsWithSample t,    CanPowBy t Integer, CanPowBy t Int,    CanDivSameType t, CanRecipSameType t,    CanAddSubMulDivBy t Rational,
src/Numeric/MixedTypes/Literals.hs view
@@ -40,9 +40,9 @@   -- * Generalised if-then-else   , HasIfThenElse(..), HasIfThenElseSameType   -- * Convenient conversions-  , CanBeInteger, integer, integers, HasIntegers, fromInteger_+  , CanBeInteger, integer, integers, HasIntegers, fromInteger_, HasIntegersWithSample, fromIntegerWithSample   , CanBeInt, int, ints-  , CanBeRational, rational, rationals, HasRationals, fromRational_+  , CanBeRational, rational, rationals, HasRationals, fromRational_, HasRationalsWithSample, fromRationalWithSample   , CanBeDouble, double, doubles   , ConvertibleExactly(..), convertExactly, convertExactlyTargetSample   , ConvertResult, ConvertError, convError@@ -133,6 +133,10 @@ fromInteger_ :: (HasIntegers t) => Integer -> t fromInteger_ = convertExactly +type HasIntegersWithSample t = ConvertibleExactly (t, Integer) t+fromIntegerWithSample :: (HasIntegersWithSample t) => t -> Integer -> t+fromIntegerWithSample sampleT n = convertExactly (sampleT, n)+ (!!) :: (CanBeInteger n) => [a] -> n -> a list !! ix = List.genericIndex list (integer ix) -- list !! ix = List.genericIndex list (P.max 0 ((integer ix) P.- 1)) -- deliberately wrong - test the test!@@ -190,6 +194,10 @@ fromRational_ :: (HasRationals t) => Rational -> t fromRational_ = convertExactly +type HasRationalsWithSample t = ConvertibleExactly (t, Rational) t+fromRationalWithSample :: (HasRationalsWithSample t) => t -> Rational -> t+fromRationalWithSample sampleT q = convertExactly (sampleT, q)+ type CanBeDouble t = Convertible t Double double :: (CanBeDouble t) => t -> Double double = convert@@ -215,18 +223,38 @@ convertExactlyTargetSample :: (ConvertibleExactly t1 t2) => t2 -> t1 -> t2 convertExactlyTargetSample _sample = convertExactly +-- HasIntegers Integer, CanBeInteger Integer instance ConvertibleExactly Integer Integer -- use CVT instance by default+-- CanBeInteger Int instance ConvertibleExactly Int Integer +-- HasIntegersWithSample Integer+instance ConvertibleExactly (Integer, Integer) Integer where+  safeConvertExactly (_sample, value) = safeConvert value++-- CanBeInt Int instance ConvertibleExactly Int Int where   safeConvertExactly n = Right n++-- CanBeRational Rational instance ConvertibleExactly Rational Rational where   safeConvertExactly q = Right q +-- HasIntegers Int instance ConvertibleExactly Integer Int instance ConvertibleExactly Int Rational+-- HasIntegers Rational instance ConvertibleExactly Integer Rational +-- HasIntegersWithSample Rational+instance ConvertibleExactly (Rational, Integer) Rational where+  safeConvertExactly (_sample, value) = safeConvert value++-- HasRationalsWithSample Rational+instance ConvertibleExactly (Rational, Rational) Rational where+  safeConvertExactly (_sample, value) = safeConvertExactly value++-- HasIntegers Double instance ConvertibleExactly Integer Double where   safeConvertExactly n =     do@@ -319,6 +347,17 @@ --   where --   safeConvertExactly = fmap pure . safeConvertExactly --++instance (HasIntegers t, Monoid es) => +  -- HasIntegersWithSample (CollectErrors es t)+  ConvertibleExactly (CollectErrors es t, Integer) (CollectErrors es t) where+  safeConvertExactly (_sample, value) = fmap pure $ safeConvertExactly value++instance (HasRationals t, Monoid es) =>   +  -- HasRationalsWithSample (CollectErrors es t)+  ConvertibleExactly (CollectErrors es t, Rational) (CollectErrors es t) where+  safeConvertExactly (_sample, value) = fmap pure $ safeConvertExactly value+  $(declForTypes   [[t| Bool |], [t| Integer |], [t| Int |], [t| Rational |], [t| Double |]]
src/Numeric/MixedTypes/Ring.hs view
@@ -42,7 +42,7 @@    HasEq t t,    HasEq t Integer, CanAddSubMulBy t Integer,    HasEq t Int, CanAddSubMulBy t Int,-   HasIntegers t) => Ring t+   HasIntegersWithSample t) => Ring t  instance Ring Integer instance Ring (CN Integer)