mixed-types-num 0.5.6.0 → 0.5.7.0
raw patch · 3 files changed
+69/−15 lines, 3 filesPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Integer.Type.Integer e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Integer.Type.Integer (Numeric.CollectErrors.Type.CN e)
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Real.Rational e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Real.Rational (Numeric.CollectErrors.Type.CN e)
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Types.Double e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Types.Double (Numeric.CollectErrors.Type.CN e)
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Types.Int e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Types.Int (Numeric.CollectErrors.Type.CN e)
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Integer.Type.Integer, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Integer.Type.Integer
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Real.Rational, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Real.Rational
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Types.Double, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Types.Double
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Types.Int, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Types.Int
- Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b e, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) (Numeric.CollectErrors.Type.CN e)
+ Numeric.MixedTypes.Power: (^^) :: CanPow t1 t2 => t1 -> t2 -> PPowType t1 t2
+ Numeric.MixedTypes.Power: class CanTestIsIntegerType t
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Integer.Type.Integer e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType e, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Integer.Type.Integer (Numeric.CollectErrors.Type.CN e)
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Real.Rational e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType e, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Real.Rational (Numeric.CollectErrors.Type.CN e)
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Types.Double e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType e, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Types.Double (Numeric.CollectErrors.Type.CN e)
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow GHC.Types.Int e, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType e, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow GHC.Types.Int (Numeric.CollectErrors.Type.CN e)
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Integer.Type.Integer, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType b) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Integer.Type.Integer
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Real.Rational, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType b) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Real.Rational
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Types.Double, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType b) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Types.Double
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b GHC.Types.Int, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType b) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) GHC.Types.Int
+ Numeric.MixedTypes.Power: instance (Numeric.MixedTypes.Power.CanPow b e, Numeric.MixedTypes.Ord.HasOrderCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Ord.HasOrderCertainly e GHC.Integer.Type.Integer, Numeric.MixedTypes.Eq.HasEqCertainly b GHC.Integer.Type.Integer, Numeric.MixedTypes.Power.CanTestIsIntegerType b, Numeric.MixedTypes.Power.CanTestIsIntegerType e, Numeric.MixedTypes.Eq.CanTestInteger e) => Numeric.MixedTypes.Power.CanPow (Numeric.CollectErrors.Type.CN b) (Numeric.CollectErrors.Type.CN e)
+ Numeric.MixedTypes.Power: instance Numeric.MixedTypes.Power.CanTestIsIntegerType GHC.Integer.Type.Integer
+ Numeric.MixedTypes.Power: instance Numeric.MixedTypes.Power.CanTestIsIntegerType GHC.Real.Rational
+ Numeric.MixedTypes.Power: instance Numeric.MixedTypes.Power.CanTestIsIntegerType GHC.Types.Double
+ Numeric.MixedTypes.Power: instance Numeric.MixedTypes.Power.CanTestIsIntegerType GHC.Types.Int
+ Numeric.MixedTypes.Power: instance Numeric.MixedTypes.Power.CanTestIsIntegerType t => Numeric.MixedTypes.Power.CanTestIsIntegerType (Numeric.CollectErrors.Type.CN t)
+ Numeric.MixedTypes.Power: isIntegerType :: CanTestIsIntegerType t => t -> Bool
+ Numeric.MixedTypes.Power: ppow :: (CanPow b e, PPowType b e ~ PowType b e) => b -> e -> PPowType b e
+ Numeric.MixedTypes.Power: type PPowType b e = PowType b e;
- Numeric.MixedTypes.Power: infixl 8 ^
+ Numeric.MixedTypes.Power: infixl 8 ^^
- Numeric.MixedTypes.Power: type family PowType b e;
+ Numeric.MixedTypes.Power: type family PPowType b e;
Files
- changelog.md +2/−0
- mixed-types-num.cabal +2/−2
- src/Numeric/MixedTypes/Power.hs +65/−13
changelog.md view
@@ -1,5 +1,7 @@ # mixed-types-num change log +* v 0.5.7 2021-05-28+ * before: n^m is rational, now: n^m is integer, n^^m is rational * v 0.5.6 2021-05-27 * add instances: mixed min/max Double $t * add instance: CanGiveUpIfVeryInaccurate Double
mixed-types-num.cabal view
@@ -4,10 +4,10 @@ -- -- see: https://github.com/sol/hpack ----- hash: bc01675c922b24362d3d11045237c87495398281a43b390a54a1d6fbb710a4cc+-- hash: b38cac48ab06aac0296ad4583bea2ac45261122fa0b952f259489586adfe528a name: mixed-types-num-version: 0.5.6.0+version: 0.5.7.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/Power.hs view
@@ -17,9 +17,10 @@ ( -- * Exponentiation CanPow(..), CanPowBy- , (^)+ , (^), (^^) , powUsingMul, integerPowCN , powUsingMulRecip+ , CanTestIsIntegerType(..) -- ** Tests , specCanPow )@@ -34,7 +35,7 @@ import Test.Hspec import Test.QuickCheck -import Numeric.CollectErrors ( CN, cn )+import Numeric.CollectErrors ( CN, cn, unCN ) import qualified Numeric.CollectErrors as CN import Numeric.MixedTypes.Literals@@ -50,20 +51,49 @@ {---- Exponentiation -----} -infixl 8 ^+infixl 8 ^, ^^ (^) :: (CanPow t1 t2) => t1 -> t2 -> PowType t1 t2 (^) = pow +(^^) :: (CanPow t1 t2) => t1 -> t2 -> PPowType t1 t2+(^^) = ppow + {-| A replacement for Prelude's binary `P.^` and `P.^^`. -} class CanPow b e where type PowType b e+ type PPowType b e+ type PPowType b e = PowType b e type PowType b e = b -- default pow :: b -> e -> PowType b e+ ppow :: b -> e -> PPowType b e+ default ppow :: (PPowType b e ~ PowType b e) => b -> e -> PPowType b e+ ppow = pow +{-|+ Ability to detect whether a numeric type is restricted to (a subset of) integers.+ + This is useful eg when checking the arguments of the power operator in the CN instance for power.+-}+class CanTestIsIntegerType t where+ isIntegerType :: t -> Bool+ isIntegerType _ = False++instance CanTestIsIntegerType t => CanTestIsIntegerType (CN t) where+ isIntegerType t = isIntegerType (unCN t)++instance CanTestIsIntegerType Int where+ isIntegerType _ = True++instance CanTestIsIntegerType Integer where+ isIntegerType _ = True++instance CanTestIsIntegerType Rational+instance CanTestIsIntegerType Double+ integerPowCN :: (HasOrderCertainly b Integer, HasOrderCertainly e Integer, HasEqCertainly b Integer, HasEqCertainly e Integer)@@ -83,10 +113,20 @@ powCN :: (HasOrderCertainly b Integer, HasOrderCertainly e Integer,- HasEqCertainly b Integer, CanTestInteger e)+ HasEqCertainly b Integer, CanTestIsIntegerType b, CanTestIsIntegerType e, CanTestInteger e) => (b -> e -> r) -> CN b -> CN e -> CN r powCN unsafePow b e+ | isIntegerType b && isIntegerType e && e !<! 0 =+ CN.noValueNumErrorCertain $ CN.OutOfDomain "illegal integer pow: negative exponent, consider using ppow or (^^)"+ | otherwise = ppowCN unsafePow b e++ppowCN ::+ (HasOrderCertainly b Integer, HasOrderCertainly e Integer,+ HasEqCertainly b Integer, CanTestInteger e)+ =>+ (b -> e -> r) -> CN b -> CN e -> CN r+ppowCN unsafePow b e | b !==! 0 && e !<=! 0 = CN.noValueNumErrorCertain $ CN.OutOfDomain "illegal pow: 0^e with e <= 0" | b !<! 0 && certainlyNotInteger e =@@ -155,14 +195,20 @@ (?==?$) = printArgsIfFails2 "?==?" (?==?) instance CanPow Integer Integer where - type PowType Integer Integer = Rational- pow b = (P.^^) (rational b)+ type PowType Integer Integer = Integer+ type PPowType Integer Integer = Rational+ pow b = (P.^) b+ ppow b = (P.^^) (rational b) instance CanPow Integer Int where- type PowType Integer Int = Rational- pow b = (P.^^) (rational b)+ type PowType Integer Int = Integer+ type PPowType Integer Int = Rational+ pow b = (P.^) b+ ppow b = (P.^^) (rational b) instance CanPow Int Integer where- type PowType Int Integer = Rational- pow b = (P.^^) (rational b)+ type PowType Int Integer = Integer+ type PPowType Int Integer = Rational+ pow b = (P.^) (integer b)+ ppow b = (P.^^) (rational b) instance CanPow Int Int where type PowType Int Int = Rational pow b = (P.^^) (rational b)@@ -202,31 +248,37 @@ instance (CanPow b e, HasOrderCertainly b Integer, HasOrderCertainly e Integer,- HasEqCertainly b Integer, CanTestInteger e)+ HasEqCertainly b Integer, CanTestIsIntegerType b, CanTestIsIntegerType e, CanTestInteger e) => CanPow (CN b) (CN e) where type PowType (CN b) (CN e) = CN (PowType b e)+ type PPowType (CN b) (CN e) = CN (PPowType b e) pow = powCN pow+ ppow = ppowCN ppow $(declForTypes [[t| Integer |], [t| Int |], [t| Rational |], [t| Double |]] (\ t -> [d| instance- (CanPow $t e, HasOrderCertainly e Integer, CanTestInteger e)+ (CanPow $t e, HasOrderCertainly e Integer, CanTestIsIntegerType e, CanTestInteger e) => CanPow $t (CN e) where type PowType $t (CN e) = CN (PowType $t e) pow b e = powCN pow (cn b) e+ type PPowType $t (CN e) = CN (PPowType $t e)+ ppow b e = ppowCN ppow (cn b) e instance- (CanPow b $t, HasOrderCertainly b Integer, HasEqCertainly b Integer)+ (CanPow b $t, HasOrderCertainly b Integer, HasEqCertainly b Integer, CanTestIsIntegerType b) => CanPow (CN b) $t where type PowType (CN b) $t = CN (PowType b $t) pow b e = powCN pow b (cn e)+ type PPowType (CN b) $t = CN (PPowType b $t)+ ppow b e = ppowCN ppow b (cn e) |]))