-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Alternative Prelude with numeric and logic expressions typed bottom-up -- -- This package provides a version of Prelude where unary and binary -- operations such as not, +, == have their -- result type derived from the parameter type(s). -- -- See module MixedTypesNumPrelude for further documentation. @package mixed-types-num @version 0.2 -- | Template Haskell utilities module Utils.TH.DeclForTypes -- | A toy example of use: -- --
--   class HasTT t where
--     type TT t
--     getTT :: t -> TT t
--   
--   $(declForTypes
--     [[t| Integer |], [t| Int |], [t| Rational |]]
--     ( t -> [d|
--       instance HasTT $t where
--         type TT $t = ()
--         getTT _ = ()
--     |]))
--   
declForTypes :: [Q Type] -> (Q Type -> Q [Dec]) -> Q [Dec] -- | Prelude without operations that clash with MixedTypes module Numeric.MixedTypes.PreludeHiding module Control.CollectErrors -- | A wrapper around values which can accommodate a list of (potential) -- errors that have (maybe) occurred during the computation of a value. A -- value may be missing, leaving only the error(s). -- -- Such error collection allows one to write expressions with partial -- functions (ie functions that fail for some inputs) instead of -- branching after each application of such function. Dealing with the -- errors can be moved outside the expression. If the error data contain -- enough information, their list can be used to trace the source of the -- errors. data CollectErrors es v CollectErrors :: Maybe v -> es -> CollectErrors es v [getMaybeValueCE] :: CollectErrors es v -> Maybe v [getErrorsCE] :: CollectErrors es v -> es type SuitableForCE es = (Monoid es, Eq es, Show es) noValueCE :: es -> CollectErrors es v prependErrorsCE :: (Monoid es) => es -> CollectErrors es v -> CollectErrors es v filterValuesWithoutErrorCE :: (SuitableForCE es) => [CollectErrors es v] -> [v] -- | A safe way to get a value out of the CollectErrors wrapper. getValueIfNoErrorCE :: (SuitableForCE es) => CollectErrors es v -> (v -> t) -> (es -> t) -> t ce2ConvertResult :: (Typeable t, Show t, SuitableForCE es) => CollectErrors es t -> Either ConvertError t -- | A mechanism for adding and removing CollectErrors to a type in a -- manner that depends on the shape of the type, especially whether it -- already has CollectErrors. class (Monoid es) => CanEnsureCE es a where type EnsureCE es a type EnsureNoCE es a type EnsureCE es a = CollectErrors es a type EnsureNoCE es a = a ensureCE _ = pure deEnsureCE _ (CollectErrors mv es) = case mv of { Just v | es == mempty -> Right v _ -> Left es } ensureNoCE _ = Right noValueECE _ = noValueCE where { type family EnsureCE es a; type family EnsureNoCE es a; type EnsureCE es a = CollectErrors es a; type EnsureNoCE es a = a; } -- | Translate a value of a type a to a value of a type -- EnsureCE es a. ensureCE :: CanEnsureCE es a => Maybe es -> a -> EnsureCE es a -- | Translate a value of a type a to a value of a type -- EnsureCE es a. ensureCE :: (CanEnsureCE es a, EnsureCE es a ~ CollectErrors es a) => Maybe es -> a -> EnsureCE es a deEnsureCE :: CanEnsureCE es a => Maybe es -> EnsureCE es a -> Either es a deEnsureCE :: (CanEnsureCE es a, EnsureCE es a ~ CollectErrors es a, Eq es) => Maybe es -> EnsureCE es a -> Either es a ensureNoCE :: CanEnsureCE es a => Maybe es -> a -> Either es (EnsureNoCE es a) ensureNoCE :: (CanEnsureCE es a, EnsureNoCE es a ~ a, Eq es) => Maybe es -> a -> Either es (EnsureNoCE es a) -- | Make CollectErrors record with no value, only errors. noValueECE :: CanEnsureCE es a => Maybe a -> es -> EnsureCE es a -- | Make CollectErrors record with no value, only errors. noValueECE :: (CanEnsureCE es a, EnsureCE es a ~ CollectErrors es a) => Maybe a -> es -> CollectErrors es a -- | An unsafe way to get a value out of an CollectErrors wrapper. getValueOrThrowErrorsNCE :: (SuitableForCE es, CanEnsureCE es v, Show v) => Maybe es -> v -> (EnsureNoCE es v) -- | Add error collection support to an unary function whose result may -- already have collected errors. lift1CE :: (SuitableForCE es, CanEnsureCE es c) => (a -> c) -> (CollectErrors es a) -> (EnsureCE es c) -- | Add error collection support to a binary function whose result may -- already have collected errors. lift2CE :: (SuitableForCE es, CanEnsureCE es c) => (a -> b -> c) -> (CollectErrors es a) -> (CollectErrors es b) -> (EnsureCE es c) -- | Add error collection support to a binary function whose result may -- already have collected errors. A version where the second operand is -- not lifted, only the first one. lift2TCE :: (SuitableForCE es, CanEnsureCE es c) => (a -> b -> c) -> (CollectErrors es a) -> b -> (EnsureCE es c) -- | Add error collection support to a binary function whose result may -- already have collected errors. A version where the first operand is -- not lifted, only the second one. lift2TLCE :: (SuitableForCE es, CanEnsureCE es c) => (a -> b -> c) -> a -> (CollectErrors es b) -> (EnsureCE es c) instance (GHC.Show.Show v, Control.CollectErrors.SuitableForCE es) => GHC.Show.Show (Control.CollectErrors.CollectErrors es v) instance GHC.Base.Functor (Control.CollectErrors.CollectErrors es) instance GHC.Base.Monoid es => GHC.Base.Applicative (Control.CollectErrors.CollectErrors es) instance GHC.Base.Monoid es => GHC.Base.Monad (Control.CollectErrors.CollectErrors es) instance (Test.QuickCheck.Arbitrary.Arbitrary t, GHC.Base.Monoid es) => Test.QuickCheck.Arbitrary.Arbitrary (Control.CollectErrors.CollectErrors es t) instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es (Control.CollectErrors.CollectErrors es a) instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es GHC.Types.Int instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es GHC.Integer.Type.Integer instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es GHC.Real.Rational instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es GHC.Types.Double instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es GHC.Types.Bool instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es GHC.Types.Char instance Control.CollectErrors.SuitableForCE es => Control.CollectErrors.CanEnsureCE es () instance (Control.CollectErrors.SuitableForCE es, Control.CollectErrors.CanEnsureCE es a) => Control.CollectErrors.CanEnsureCE es (GHC.Base.Maybe a) -- | A type of numeric errors to be collected. module Numeric.CollectErrors data ErrorCertaintyLevel ErrorCertain :: ErrorCertaintyLevel ErrorPotential :: ErrorCertaintyLevel data NumError DivByZero :: NumError OutOfRange :: String -> NumError NumError :: String -> NumError type NumErrors = [(ErrorCertaintyLevel, NumError)] sample_NumErrors :: Maybe [(ErrorCertaintyLevel, NumError)] type CN = CollectErrors NumErrors type CanEnsureCN = CanEnsureCE NumErrors type EnsureCN a = EnsureCE NumErrors a type EnsureNoCN a = EnsureNoCE NumErrors a -- | Translate a value of a type a to a value of a type -- CollectNumErrors a except when a already is a -- CollectNumErrors type, in which case the value is left as is. ensureCN :: (CanEnsureCN v) => v -> EnsureCN v -- | Translate a value of a type EnsureCN es a to a, -- throwing an exception if there was an error. If a is a -- CollectNumErrors type, then this is just an identity. deEnsureCN :: (CanEnsureCN v) => EnsureCN v -> Either NumErrors v -- | Translate a value of a type a to a value of a type -- CollectNumErrors a except when a already is a -- CollectNumErrors type, in which case the value is left as is. ensureNoCN :: (CanEnsureCN v) => v -> Either NumErrors (EnsureNoCN v) noValueCN :: NumErrors -> CN v -- | Construct an empty wrapper indicating that given error has certainly -- occurred. noValueNumErrorCertainCN :: NumError -> CN v -- | Construct an empty wrapper indicating that given error may have -- occurred. noValueNumErrorPotentialCN :: NumError -> CN v getMaybeValueCN :: CN v -> Maybe v getErrorsCN :: CN v -> NumErrors prependErrorsCN :: NumErrors -> CN v -> CN v noValueECN :: (CanEnsureCN v) => Maybe v -> NumErrors -> EnsureCN v -- | Construct an empty wrapper indicating that given error has certainly -- occurred. noValueNumErrorCertainECN :: (CanEnsureCN v) => Maybe v -> NumError -> EnsureCN v -- | Construct an empty wrapper indicating that given error may have -- occurred. noValueNumErrorPotentialECN :: (CanEnsureCN v) => Maybe v -> NumError -> EnsureCN v -- | Wrap a value in the CollectNumErrors wrapper. cn :: (CanEnsureCN v) => v -> EnsureCN v -- | An unsafe way to get a value out of the CollectNumErrors wrapper. deCN :: (CanEnsureCN v) => EnsureCN v -> Either NumErrors v -- | An unsafe way to get a value out of the CollectNumErrors wrapper. (~!) :: (CanEnsureCN v, Show v) => v -> EnsureNoCN v instance GHC.Classes.Eq Numeric.CollectErrors.ErrorCertaintyLevel instance GHC.Classes.Eq Numeric.CollectErrors.NumError instance GHC.Show.Show Numeric.CollectErrors.NumError instance GHC.Show.Show Numeric.CollectErrors.ErrorCertaintyLevel -- | This module defines fixed-type integer and rational literals. This is -- useful when deriving the type of an expression bottom-up. Eg we would -- not be able to write 1 < x when the type of < -- does not force the two sides to be of the same type. We would need to -- write eg (1::Integer) < x with Prelude's generic literals. -- -- Moreover, convenient conversion functions are provided for the most -- common numeric types. Thus one can say eg: -- -- -- -- To avoid integer overflow, no aritmetic operations return Int. -- Nevertheless, one can usually mix Int with other types in -- expressions. -- -- Any approximate arithmetic, ie arithmetic involving Doubles, returns -- values of type Double. Double values cannot be easily -- converted to exact types such as Rational or Integer so -- that all such conversions are clearly visible as labelled as inexact. module Numeric.MixedTypes.Literals -- | Replacement for fromInteger using the RebindableSyntax -- extension. This version of fromInteger arranges that integer literals -- are always of type Integer. fromInteger :: Integer -> Integer -- | Replacement for fromRational using the RebindableSyntax -- extension. This version of fromRational arranges that rational -- literals are always of type Rational. fromRational :: Rational -> Rational -- | Restore if-then-else with RebindableSyntax class HasIfThenElse b t ifThenElse :: HasIfThenElse b t => b -> t -> t -> t type CanBeInteger t = ConvertibleExactly t Integer integer :: (CanBeInteger t) => t -> Integer integers :: (CanBeInteger t) => [t] -> [Integer] type HasIntegers t = ConvertibleExactly Integer t fromInteger_ :: (HasIntegers t) => Integer -> t type CanBeInt t = ConvertibleExactly t Int int :: (CanBeInt t) => t -> Int ints :: (CanBeInt t) => [t] -> [Int] type CanBeRational t = ConvertibleExactly t Rational rational :: (CanBeRational t) => t -> Rational rationals :: (CanBeRational t) => [t] -> [Rational] type HasRationals t = ConvertibleExactly Rational t fromRational_ :: (HasRationals t) => Rational -> t type CanBeDouble t = Convertible t Double double :: (CanBeDouble t) => t -> Double doubles :: (CanBeDouble t) => [t] -> [Double] -- | Define our own ConvertibleExactly since convertible is too relaxed for -- us. For example, convertible allows conversion from Rational to -- Integer, rounding to nearest integer. We prefer to allow only exact -- conversions. class ConvertibleExactly t1 t2 where safeConvertExactly = safeConvert safeConvertExactly :: ConvertibleExactly t1 t2 => t1 -> ConvertResult t2 safeConvertExactly :: (ConvertibleExactly t1 t2, Convertible t1 t2) => t1 -> ConvertResult t2 convertExactly :: (ConvertibleExactly t1 t2) => t1 -> t2 -- | The result of a safe conversion via safeConvert. type ConvertResult a = Either ConvertError a -- | How we indicate that there was an error. data ConvertError :: * convError :: (Show a, Typeable * a, Typeable * b) => String -> a -> ConvertResult b (!!) :: (CanBeInteger t) => [a] -> t -> a -- | HSpec properties that each implementation of CanBeInteger should -- satisfy. specCanBeInteger :: (CanBeInteger t, Show t, Arbitrary t) => T t -> Spec printArgsIfFails2 :: (Testable prop, Show a, Show b) => String -> (a -> b -> prop) -> (a -> b -> Property) -- | A runtime representative of type t. Used for specialising -- polymorphic tests to concrete types. data T t T :: String -> T t tInt :: T Int tInteger :: T Integer tRational :: T Rational tDouble :: T Double tBool :: T Bool tMaybeBool :: T (Maybe Bool) tMaybeMaybeBool :: T (Maybe (Maybe Bool)) convertFirst :: (ConvertibleExactly a b) => (b -> b -> c) -> (a -> b -> c) convertSecond :: (ConvertibleExactly b a) => (a -> a -> c) -> (a -> b -> c) convertFirstUsing :: (a -> b -> b) -> (b -> b -> c) -> (a -> b -> c) convertSecondUsing :: (a -> b -> a) -> (a -> a -> c) -> (a -> b -> c) instance (Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Bool t0, GHC.Base.Monoid es0) => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Bool (Control.CollectErrors.CollectErrors es0 t0) instance (Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer t0, GHC.Base.Monoid es0) => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 t0) instance (Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int t0, GHC.Base.Monoid es0) => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int (Control.CollectErrors.CollectErrors es0 t0) instance (Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Real.Rational t0, GHC.Base.Monoid es0) => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 t0) instance (Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Double t0, GHC.Base.Monoid es0) => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Double (Control.CollectErrors.CollectErrors es0 t0) instance Numeric.MixedTypes.Literals.HasIfThenElse GHC.Types.Bool t instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Double GHC.Types.Double module Numeric.MixedTypes.Bool -- | A type constraint synonym that stipulates that the type behaves very -- much like Bool, except it does not necessarily satisfy the law of -- excluded middle, which means that the type can contain a "do-not-know" -- value. -- -- Examples: Bool, Maybe Bool, Maybe (Maybe -- Bool), CollectErrors Bool type IsBool t = (HasBools t, CanNegSameType t, CanAndOrSameType t) -- | HSpec properties that each implementation of IsBool should satisfy. specIsBool :: (IsBool t, CanTestCertainly t, Show t, Serial IO t) => T t -> Spec type HasBools t = ConvertibleExactly Bool t -- | Tests for truth or falsity. Beware, when isCertainlyTrue -- returns False, it does not mean that the proposition is -- false. It usually means that we failed to prove the proposition. class (HasBools t) => CanTestCertainly t isCertainlyTrue :: CanTestCertainly t => t -> Bool isCertainlyFalse :: CanTestCertainly t => t -> Bool -- | HSpec properties that each implementation of CanTestCertainly should -- satisfy. specCanTestCertainly :: (CanTestCertainly t) => T t -> Spec -- | Compound type constraint useful for test definition. type CanTestCertainlyX t = (CanTestCertainly t, Show t, Serial IO t) isNotTrue :: (CanTestCertainly t) => t -> Bool isNotFalse :: (CanTestCertainly t) => t -> Bool -- | If l is certainly True, then r is also certainly True. stronglyImplies :: (CanTestCertainly t1, CanTestCertainly t2) => t1 -> t2 -> Bool stronglyEquivalentTo :: (CanTestCertainly t1, CanTestCertainly t2) => t1 -> t2 -> Bool -- | If l is certainly True, then r is not certainly False. weaklyImplies :: (CanTestCertainly t1, CanTestCertainly t2) => t1 -> t2 -> Bool weaklyEquivalentTo :: (CanTestCertainly t1, CanTestCertainly t2) => t1 -> t2 -> Bool -- | This is negation is both the numeric negation as well as the Boolean -- negation. Example of non-standard Boolean negation: -- --
--   negate (Just True) = Just False
--   
--   
class CanNeg t where type NegType t type NegType t = t where { type family NegType t; type NegType t = t; } negate :: CanNeg t => t -> NegType t -- | A synonym of negate. not :: (CanNeg t) => t -> NegType t type CanNegSameType t = (CanNeg t, NegType t ~ t) -- | HSpec properties that each Boolean implementation of CanNeg should -- satisfy. specCanNegBool :: (CanNegBoolX t, CanNegBoolX (NegType t)) => T t -> Spec -- | Compound type constraint useful for test definition. type CanNegBoolX t = (CanNeg t, CanTestCertainlyX t, CanTestCertainlyX (NegType t)) type CanAndOr t1 t2 = (CanAndOrAsymmetric t1 t2, CanAndOrAsymmetric t2 t1, AndOrType t1 t2 ~ AndOrType t2 t1) -- | Binary logical and and or for generalised Booleans. For -- example: -- --
--   (Just True) && False = Just False
--   (Just (Just True)) || False = (Just (Just True))
--   
--   
class CanAndOrAsymmetric t1 t2 where type AndOrType t1 t2 where { type family AndOrType t1 t2; } and2 :: CanAndOrAsymmetric t1 t2 => t1 -> t2 -> AndOrType t1 t2 or2 :: CanAndOrAsymmetric t1 t2 => t1 -> t2 -> AndOrType t1 t2 -- | A synonym of and2. (&&) :: (CanAndOrAsymmetric a b) => a -> b -> AndOrType a b infixr 3 && -- | A synonym of or2. (||) :: (CanAndOrAsymmetric a b) => a -> b -> AndOrType a b infixr 2 || type CanAndOrWith t1 t2 = (CanAndOr t1 t2, AndOrType t1 t2 ~ t1) type CanAndOrSameType t = CanAndOrWith t t and :: (CanAndOrSameType t, CanTestCertainly t) => [t] -> t or :: (CanAndOrSameType t, CanTestCertainly t) => [t] -> t -- | HSpec properties that each implementation of CanAndOr should satisfy. specCanAndOr :: (CanAndOrX t1 t1, CanAndOrX t1 t2, CanAndOrX t2 t1, CanAndOrX t1 t3, CanAndOrX t2 t3, CanAndOrX (AndOrType t1 t2) t3, CanAndOrX t1 (AndOrType t2 t3), CanAndOrX (AndOrType t1 t2) (AndOrType t1 t3)) => T t1 -> T t2 -> T t3 -> Spec -- | HSpec properties that each implementation of CanAndOr should satisfy. specCanAndOrNotMixed :: (CanAndOrX t t, CanAndOrX (AndOrType t t) t, CanAndOrX t (AndOrType t t), CanAndOrX (AndOrType t t) (AndOrType t t)) => T t -> Spec -- | Compound type constraint useful for test definition. type CanAndOrX t1 t2 = (CanAndOr t1 t2, CanNeg t1, CanNeg t2, CanAndOr (NegType t1) t2, CanAndOr t1 (NegType t2), CanAndOr (NegType t1) (NegType t2), CanTestCertainlyX t1, CanTestCertainlyX t2, CanTestCertainlyX (AndOrType t1 t2), CanTestCertainlyX (NegType (AndOrType t1 t2)), CanTestCertainlyX (AndOrType (NegType t1) t2), CanTestCertainlyX (AndOrType t1 (NegType t2)), CanTestCertainlyX (AndOrType (NegType t1) (NegType t2))) instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Bool GHC.Types.Bool instance Numeric.MixedTypes.Bool.CanTestCertainly GHC.Types.Bool instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Bool t => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Bool (GHC.Base.Maybe t) instance Numeric.MixedTypes.Bool.CanTestCertainly t => Numeric.MixedTypes.Bool.CanTestCertainly (GHC.Base.Maybe t) instance (Numeric.MixedTypes.Bool.CanTestCertainly t, Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Bool.CanTestCertainly (Control.CollectErrors.CollectErrors es t) instance Numeric.MixedTypes.Bool.CanNeg GHC.Types.Bool instance Numeric.MixedTypes.Bool.CanNeg t => Numeric.MixedTypes.Bool.CanNeg (GHC.Base.Maybe t) instance (Numeric.MixedTypes.Bool.CanNeg t, Control.CollectErrors.SuitableForCE es, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Bool.NegType t)) => Numeric.MixedTypes.Bool.CanNeg (Control.CollectErrors.CollectErrors es t) instance Numeric.MixedTypes.Bool.CanAndOrAsymmetric GHC.Types.Bool GHC.Types.Bool instance (Numeric.MixedTypes.Bool.CanAndOrAsymmetric t1 t2, Numeric.MixedTypes.Bool.CanTestCertainly t1, Numeric.MixedTypes.Bool.CanTestCertainly t2, Numeric.MixedTypes.Bool.CanTestCertainly (Numeric.MixedTypes.Bool.AndOrType t1 t2)) => Numeric.MixedTypes.Bool.CanAndOrAsymmetric (GHC.Base.Maybe t1) (GHC.Base.Maybe t2) instance (Numeric.MixedTypes.Bool.CanAndOrAsymmetric GHC.Types.Bool t2, Numeric.MixedTypes.Bool.CanTestCertainly t2, Numeric.MixedTypes.Bool.CanTestCertainly (Numeric.MixedTypes.Bool.AndOrType GHC.Types.Bool t2)) => Numeric.MixedTypes.Bool.CanAndOrAsymmetric GHC.Types.Bool (GHC.Base.Maybe t2) instance (Numeric.MixedTypes.Bool.CanAndOrAsymmetric t1 GHC.Types.Bool, Numeric.MixedTypes.Bool.CanTestCertainly t1, Numeric.MixedTypes.Bool.CanTestCertainly (Numeric.MixedTypes.Bool.AndOrType t1 GHC.Types.Bool)) => Numeric.MixedTypes.Bool.CanAndOrAsymmetric (GHC.Base.Maybe t1) GHC.Types.Bool instance (Numeric.MixedTypes.Bool.CanAndOrAsymmetric t1 t2, Control.CollectErrors.SuitableForCE es, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Bool.AndOrType t1 t2)) => Numeric.MixedTypes.Bool.CanAndOrAsymmetric (Control.CollectErrors.CollectErrors es t1) (Control.CollectErrors.CollectErrors es t2) instance (Numeric.MixedTypes.Bool.CanAndOrAsymmetric t1 GHC.Types.Bool, Control.CollectErrors.SuitableForCE es, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Bool.AndOrType t1 GHC.Types.Bool)) => Numeric.MixedTypes.Bool.CanAndOrAsymmetric (Control.CollectErrors.CollectErrors es t1) GHC.Types.Bool instance (Numeric.MixedTypes.Bool.CanAndOrAsymmetric GHC.Types.Bool t2, Control.CollectErrors.SuitableForCE es, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Bool.AndOrType GHC.Types.Bool t2)) => Numeric.MixedTypes.Bool.CanAndOrAsymmetric GHC.Types.Bool (Control.CollectErrors.CollectErrors es t2) module Numeric.MixedTypes.Eq type HasEq t1 t2 = (HasEqAsymmetric t1 t2, HasEqAsymmetric t2 t1, EqCompareType t1 t2 ~ EqCompareType t2 t1) class (IsBool (EqCompareType a b)) => HasEqAsymmetric a b where type EqCompareType a b type EqCompareType a b = Bool equalTo = (==) notEqualTo a b = not $ equalTo a b where { type family EqCompareType a b; type EqCompareType a b = Bool; } equalTo :: HasEqAsymmetric a b => a -> b -> (EqCompareType a b) equalTo :: (HasEqAsymmetric a b, EqCompareType a b ~ Bool, a ~ b, Eq a) => a -> b -> Bool notEqualTo :: HasEqAsymmetric a b => a -> b -> (EqCompareType a b) notEqualTo :: (HasEqAsymmetric a b, CanNegSameType (EqCompareType a b)) => a -> b -> (EqCompareType a b) (==) :: (HasEqAsymmetric a b) => a -> b -> EqCompareType a b infix 4 == (/=) :: (HasEqAsymmetric a b) => a -> b -> EqCompareType a b infix 4 /= type HasEqCertainly t1 t2 = (HasEq t1 t2, CanTestCertainly (EqCompareType t1 t2)) type HasEqCertainlyAsymmetric t1 t2 = (HasEqAsymmetric t1 t2, CanTestCertainly (EqCompareType t1 t2)) type HasEqCertainlyCE es t1 t2 = (HasEqCertainly t1 t2, HasEqCertainly (EnsureCE es t1) (EnsureCE es t2)) type HasEqCertainlyCN t1 t2 = HasEqCertainlyCE NumErrors t1 t2 notCertainlyDifferentFrom :: (HasEqCertainlyAsymmetric a b) => a -> b -> Bool certainlyEqualTo :: (HasEqCertainlyAsymmetric a b) => a -> b -> Bool certainlyNotEqualTo :: (HasEqCertainlyAsymmetric a b) => a -> b -> Bool (?==?) :: (HasEqCertainlyAsymmetric a b) => a -> b -> Bool infix 4 ?==? (!==!) :: (HasEqCertainlyAsymmetric a b) => a -> b -> Bool infix 4 !==! (!/=!) :: (HasEqCertainlyAsymmetric a b) => a -> b -> Bool infix 4 !/=! -- | HSpec properties that each implementation of HasEq should satisfy. specHasEq :: (HasEqX t1 t1, HasEqX t1 t2, HasEqX t2 t1, HasEqX t1 t3, HasEqX t2 t3, CanAndOrX (EqCompareType t1 t2) (EqCompareType t2 t3)) => T t1 -> T t2 -> T t3 -> Spec -- | HSpec properties that each implementation of HasEq should satisfy. specHasEqNotMixed :: (HasEqX t t, CanAndOrX (EqCompareType t t) (EqCompareType t t)) => T t -> Spec -- | Compound type constraint useful for test definition. type HasEqX t1 t2 = (HasEqCertainly t1 t2, Show t1, Arbitrary t1, Show t2, Arbitrary t2) -- | HSpec property of there-and-back conversion. specConversion :: (Arbitrary t1, Show t1, HasEqCertainly t1 t1) => T t1 -> T t2 -> (t1 -> t2) -> (t2 -> t1) -> Spec class CanTestNaN t where isNaN = isNaN isNaN :: CanTestNaN t => t -> Bool isNaN :: (CanTestNaN t, RealFloat t) => t -> Bool class CanTestFinite t where isInfinite = isInfinite isFinite x = (not $ isNaN x) && (not $ isInfinite x) isInfinite :: CanTestFinite t => t -> Bool isInfinite :: (CanTestFinite t, RealFloat t) => t -> Bool isFinite :: CanTestFinite t => t -> Bool isFinite :: (CanTestFinite t, RealFloat t) => t -> Bool class CanTestInteger t where certainlyInteger s = case certainlyIntegerGetIt s of { Just _ -> True _ -> False } certainlyNotInteger :: CanTestInteger t => t -> Bool certainlyInteger :: CanTestInteger t => t -> Bool certainlyIntegerGetIt :: CanTestInteger t => t -> Maybe Integer class CanTestZero t where isCertainlyZero a = isCertainlyTrue (a == 0) isCertainlyNonZero a = isCertainlyTrue (a /= 0) isCertainlyZero :: CanTestZero t => t -> Bool isCertainlyNonZero :: CanTestZero t => t -> Bool isCertainlyZero :: (CanTestZero t, HasEqCertainly t Integer) => t -> Bool isCertainlyNonZero :: (CanTestZero t, HasEqCertainly t Integer) => t -> Bool -- | HSpec properties that each implementation of CanTestZero should -- satisfy. specCanTestZero :: (CanTestZero t, ConvertibleExactly Integer t) => T t -> Spec class CanPickNonZero t where pickNonZero list = aux list where aux ((a, b) : rest) | isCertainlyNonZero a = Just (a, b) | otherwise = aux rest aux [] = Nothing -- | Given a list [(a1,b1),(a2,b2),...] and assuming that at least -- one of a1,a2,... is non-zero, pick one of them and return the -- corresponding pair (ai,bi). -- -- If none of a1,a2,... is zero, either throws an exception or -- loops forever. -- -- The default implementation is based on a CanTestZero instance -- and is not parallel. pickNonZero :: CanPickNonZero t => [(t, s)] -> Maybe (t, s) -- | Given a list [(a1,b1),(a2,b2),...] and assuming that at least -- one of a1,a2,... is non-zero, pick one of them and return the -- corresponding pair (ai,bi). -- -- If none of a1,a2,... is zero, either throws an exception or -- loops forever. -- -- The default implementation is based on a CanTestZero instance -- and is not parallel. pickNonZero :: (CanPickNonZero t, CanTestZero t, Show t) => [(t, s)] -> Maybe (t, s) -- | HSpec properties that each implementation of CanPickNonZero should -- satisfy. specCanPickNonZero :: (CanPickNonZero t, CanTestZero t, ConvertibleExactly Integer t, Show t, Arbitrary t) => T t -> Spec instance (Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Bool b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Types.Bool b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Types.Bool b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Bool (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a0 GHC.Types.Bool, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Types.Bool), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Types.Bool)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Bool instance (Numeric.MixedTypes.Eq.HasEqAsymmetric (GHC.Base.Maybe GHC.Types.Bool) b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType (GHC.Base.Maybe GHC.Types.Bool) b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType (GHC.Base.Maybe GHC.Types.Bool) b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric (GHC.Base.Maybe GHC.Types.Bool) (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a0 (GHC.Base.Maybe GHC.Types.Bool), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 (GHC.Base.Maybe GHC.Types.Bool)), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 (GHC.Base.Maybe GHC.Types.Bool))), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric (Control.CollectErrors.CollectErrors es0 a0) (GHC.Base.Maybe GHC.Types.Bool) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Integer.Type.Integer b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Integer.Type.Integer b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Integer.Type.Integer), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Integer.Type.Integer)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Types.Int b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Types.Int b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Types.Int), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Types.Int)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Real.Rational b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Real.Rational b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Real.Rational), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Real.Rational)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Types.Double b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType GHC.Types.Double b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Types.Double), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Eq.EqCompareType a0 GHC.Types.Double)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Eq.HasEqAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance Numeric.MixedTypes.Eq.CanTestNaN GHC.Types.Double instance Numeric.MixedTypes.Eq.CanTestFinite GHC.Types.Double instance Numeric.MixedTypes.Eq.CanTestNaN GHC.Real.Rational instance Numeric.MixedTypes.Eq.CanTestFinite GHC.Real.Rational instance (Numeric.MixedTypes.Eq.CanTestNaN t, Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Eq.CanTestNaN (Control.CollectErrors.CollectErrors es t) instance (Numeric.MixedTypes.Eq.CanTestFinite t, Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Eq.CanTestFinite (Control.CollectErrors.CollectErrors es t) instance Numeric.MixedTypes.Eq.CanTestInteger GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.CanTestInteger GHC.Types.Int instance Numeric.MixedTypes.Eq.CanTestInteger GHC.Real.Rational instance Numeric.MixedTypes.Eq.CanTestInteger GHC.Types.Double instance (Numeric.MixedTypes.Eq.CanTestInteger t, Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Eq.CanTestInteger (Control.CollectErrors.CollectErrors es t) instance Numeric.MixedTypes.Eq.CanTestZero GHC.Types.Int instance Numeric.MixedTypes.Eq.CanTestZero GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.CanTestZero GHC.Real.Rational instance Numeric.MixedTypes.Eq.CanTestZero GHC.Types.Double instance (Numeric.MixedTypes.Eq.CanTestZero t, Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Eq.CanTestZero (Control.CollectErrors.CollectErrors es t) instance Numeric.MixedTypes.Eq.CanPickNonZero GHC.Types.Int instance Numeric.MixedTypes.Eq.CanPickNonZero GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.CanPickNonZero GHC.Real.Rational instance (Numeric.MixedTypes.Eq.CanPickNonZero a, Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Eq.CanPickNonZero (Control.CollectErrors.CollectErrors es a) instance Numeric.MixedTypes.Eq.HasEqAsymmetric () () instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Bool GHC.Types.Bool instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Char GHC.Types.Char instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Double GHC.Types.Double instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Double GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Double GHC.Types.Int instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a1 b1, Numeric.MixedTypes.Eq.HasEqAsymmetric a2 b2, Numeric.MixedTypes.Bool.CanAndOrAsymmetric (Numeric.MixedTypes.Eq.EqCompareType a1 b1) (Numeric.MixedTypes.Eq.EqCompareType a2 b2), Numeric.MixedTypes.Bool.IsBool (Numeric.MixedTypes.Bool.AndOrType (Numeric.MixedTypes.Eq.EqCompareType a1 b1) (Numeric.MixedTypes.Eq.EqCompareType a2 b2))) => Numeric.MixedTypes.Eq.HasEqAsymmetric (a1, a2) (b1, b2) instance Numeric.MixedTypes.Eq.HasEqAsymmetric ((a1, a2), a3) ((b1, b2), b3) => Numeric.MixedTypes.Eq.HasEqAsymmetric (a1, a2, a3) (b1, b2, b3) instance Numeric.MixedTypes.Eq.HasEqAsymmetric ((a1, a2, a3), a4) ((b1, b2, b3), b4) => Numeric.MixedTypes.Eq.HasEqAsymmetric (a1, a2, a3, a4) (b1, b2, b3, b4) instance Numeric.MixedTypes.Eq.HasEqAsymmetric ((a1, a2, a3, a4), a5) ((b1, b2, b3, b4), b5) => Numeric.MixedTypes.Eq.HasEqAsymmetric (a1, a2, a3, a4, a5) (b1, b2, b3, b4, b5) instance Numeric.MixedTypes.Eq.HasEqAsymmetric a b => Numeric.MixedTypes.Eq.HasEqAsymmetric [a] [b] instance Numeric.MixedTypes.Eq.HasEqAsymmetric a b => Numeric.MixedTypes.Eq.HasEqAsymmetric (GHC.Base.Maybe a) (GHC.Base.Maybe b) instance (Numeric.MixedTypes.Eq.HasEqAsymmetric a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Eq.EqCompareType a b), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es (Numeric.MixedTypes.Eq.EqCompareType a b)), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Eq.HasEqAsymmetric (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) module Numeric.MixedTypes.Ord type HasOrder t1 t2 = (HasOrderAsymmetric t1 t2, HasOrderAsymmetric t2 t1, OrderCompareType t1 t2 ~ OrderCompareType t2 t1) class (IsBool (OrderCompareType a b)) => HasOrderAsymmetric a b where type OrderCompareType a b type OrderCompareType a b = Bool lessThan = (<) greaterThan a b = lessThan b a leq = (<=) geq a b = leq b a where { type family OrderCompareType a b; type OrderCompareType a b = Bool; } lessThan :: HasOrderAsymmetric a b => a -> b -> (OrderCompareType a b) lessThan :: (HasOrderAsymmetric a b, OrderCompareType a b ~ Bool, a ~ b, Ord a) => a -> b -> Bool greaterThan :: HasOrderAsymmetric a b => a -> b -> (OrderCompareType a b) greaterThan :: (HasOrderAsymmetric a b, HasOrder b a, OrderCompareType b a ~ OrderCompareType a b) => a -> b -> (OrderCompareType a b) leq :: HasOrderAsymmetric a b => a -> b -> (OrderCompareType a b) leq :: (HasOrderAsymmetric a b, OrderCompareType a b ~ Bool, a ~ b, Ord a) => a -> b -> Bool geq :: HasOrderAsymmetric a b => a -> b -> (OrderCompareType a b) geq :: (HasOrderAsymmetric a b, HasOrder b a, OrderCompareType b a ~ OrderCompareType a b) => a -> b -> (OrderCompareType a b) (>) :: (HasOrderAsymmetric a b) => a -> b -> OrderCompareType a b infix 4 > (<) :: (HasOrderAsymmetric a b) => a -> b -> OrderCompareType a b infix 4 < (<=) :: (HasOrderAsymmetric a b) => a -> b -> OrderCompareType a b infix 4 <= (>=) :: (HasOrderAsymmetric a b) => a -> b -> OrderCompareType a b infix 4 >= type HasOrderCertainlyAsymmetric t1 t2 = (HasOrderAsymmetric t1 t2, CanTestCertainly (OrderCompareType t1 t2)) type HasOrderCertainly t1 t2 = (HasOrder t1 t2, CanTestCertainly (OrderCompareType t1 t2)) type HasOrderCertainlyCE es t1 t2 = (HasOrderCertainly t1 t2, HasOrderCertainly (EnsureCE es t1) (EnsureCE es t2)) type HasOrderCertainlyCN t1 t2 = HasOrderCertainlyCE NumErrors t1 t2 (?<=?) :: (HasOrderCertainlyAsymmetric a b) => a -> b -> Bool infix 4 ?<=? (? a -> b -> Bool infix 4 ?=?) :: (HasOrderCertainlyAsymmetric a b) => a -> b -> Bool infix 4 ?>=? (?>?) :: (HasOrderCertainlyAsymmetric a b) => a -> b -> Bool infix 4 ?>? (!<=!) :: (HasOrderCertainlyAsymmetric a b) => a -> b -> Bool infix 4 !<=! (! a -> b -> Bool infix 4 !=!) :: (HasOrderCertainlyAsymmetric a b) => a -> b -> Bool infix 4 !>=! (!>!) :: (HasOrderCertainlyAsymmetric a b) => a -> b -> Bool infix 4 !>! -- | HSpec properties that each implementation of HasOrder should -- satisfy. specHasOrder :: (HasOrderX t1 t1, HasOrderX t1 t2, HasOrderX t1 t3, HasOrderX t2 t3, CanAndOrX (OrderCompareType t1 t2) (OrderCompareType t2 t3)) => T t1 -> T t2 -> T t3 -> Spec -- | HSpec properties that each implementation of HasOrder should -- satisfy. specHasOrderNotMixed :: (HasOrderX t t, CanAndOrX (OrderCompareType t t) (OrderCompareType t t)) => T t -> Spec -- | Compound type constraint useful for test definition. type HasOrderX t1 t2 = (HasOrderCertainly t1 t2, Show t1, Arbitrary t1, Show t2, Arbitrary t2) class CanTestPosNeg t where isCertainlyPositive a = isCertainlyTrue $ a > 0 isCertainlyNonNegative a = isCertainlyTrue $ a >= 0 isCertainlyNegative a = isCertainlyTrue $ a < 0 isCertainlyNonPositive a = isCertainlyTrue $ a <= 0 isCertainlyPositive :: CanTestPosNeg t => t -> Bool isCertainlyNonNegative :: CanTestPosNeg t => t -> Bool isCertainlyNegative :: CanTestPosNeg t => t -> Bool isCertainlyNonPositive :: CanTestPosNeg t => t -> Bool isCertainlyPositive :: (CanTestPosNeg t, HasOrderCertainly t Integer) => t -> Bool isCertainlyNonNegative :: (CanTestPosNeg t, HasOrderCertainly t Integer) => t -> Bool isCertainlyNegative :: (CanTestPosNeg t, HasOrderCertainly t Integer) => t -> Bool isCertainlyNonPositive :: (CanTestPosNeg t, HasOrderCertainly t Integer) => t -> Bool instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Integer.Type.Integer b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Integer.Type.Integer b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Integer.Type.Integer), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Integer.Type.Integer)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Types.Int b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Types.Int b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Types.Int), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Types.Int)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Real.Rational b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Real.Rational b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Real.Rational), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Real.Rational)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Types.Double b0), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType GHC.Types.Double b0)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Types.Double), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es0 (Numeric.MixedTypes.Ord.OrderCompareType a0 GHC.Types.Double)), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ord.HasOrderAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance Numeric.MixedTypes.Ord.CanTestPosNeg GHC.Types.Int instance Numeric.MixedTypes.Ord.CanTestPosNeg GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ord.CanTestPosNeg GHC.Real.Rational instance Numeric.MixedTypes.Ord.CanTestPosNeg GHC.Types.Double instance (Numeric.MixedTypes.Ord.CanTestPosNeg t, Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Ord.CanTestPosNeg (Control.CollectErrors.CollectErrors es t) instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Double GHC.Types.Double instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Double GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.Ord.HasOrderAsymmetric GHC.Types.Double GHC.Types.Int instance (Numeric.MixedTypes.Ord.HasOrderAsymmetric a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Ord.OrderCompareType a b), Numeric.MixedTypes.Bool.IsBool (Control.CollectErrors.EnsureCE es (Numeric.MixedTypes.Ord.OrderCompareType a b)), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Ord.HasOrderAsymmetric (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) module Numeric.MixedTypes.MinMaxAbs type CanMinMax t1 t2 = (CanMinMaxAsymmetric t1 t2, CanMinMaxAsymmetric t2 t1, MinMaxType t1 t2 ~ MinMaxType t2 t1) -- | A replacement for Prelude's min and max. If t1 = -- t2 and Ord t1, then one can use the default -- implementation to mirror Prelude's min and max. class CanMinMaxAsymmetric t1 t2 where type MinMaxType t1 t2 type MinMaxType t1 t2 = t1 min = min max = max where { type family MinMaxType t1 t2; type MinMaxType t1 t2 = t1; } min :: CanMinMaxAsymmetric t1 t2 => t1 -> t2 -> MinMaxType t1 t2 max :: CanMinMaxAsymmetric t1 t2 => t1 -> t2 -> MinMaxType t1 t2 min :: (CanMinMaxAsymmetric t1 t2, MinMaxType t1 t2 ~ t1, t1 ~ t2, Ord t1) => t1 -> t1 -> t1 max :: (CanMinMaxAsymmetric t1 t2, MinMaxType t1 t2 ~ t1, t1 ~ t2, Ord t1) => t1 -> t1 -> t1 type CanMinMaxThis t1 t2 = (CanMinMax t1 t2, MinMaxType t1 t2 ~ t1) type CanMinMaxSameType t = CanMinMaxThis t t minimum :: (CanMinMaxSameType t) => [t] -> t maximum :: (CanMinMaxSameType t) => [t] -> t -- | HSpec properties that each implementation of CanMinMax should satisfy. specCanMinMax :: (CanMinMaxXX t1 t1, CanMinMaxXX t1 t2, CanMinMaxXX t1 t3, CanMinMaxXX t2 t3, CanMinMaxXX t1 (MinMaxType t2 t3), CanMinMaxXX (MinMaxType t1 t2) t3, HasEqCertainly (MinMaxType t1 (MinMaxType t2 t3)) (MinMaxType (MinMaxType t1 t2) t3)) => T t1 -> T t2 -> T t3 -> Spec -- | HSpec properties that each implementation of CanMinMax should satisfy. specCanMinMaxNotMixed :: (CanMinMaxXX t t, CanMinMaxXX t (MinMaxType t t), HasEq (MinMaxType (MinMaxType t t) t) (MinMaxType t (MinMaxType t t))) => T t -> Spec -- | Compound type constraint useful for test definition. type CanMinMaxX t1 t2 = (CanMinMax t1 t2, Show t1, Arbitrary t1, Show t2, Arbitrary t2, Show (MinMaxType t1 t2), HasEqCertainly t1 t1, HasEqCertainly t2 t2, HasEqCertainly t1 (MinMaxType t1 t2), HasEqCertainly t2 (MinMaxType t1 t2), HasEqCertainly (MinMaxType t1 t2) (MinMaxType t1 t2), HasOrderCertainly t1 (MinMaxType t1 t2), HasOrderCertainly t2 (MinMaxType t1 t2), HasOrderCertainly (MinMaxType t1 t2) (MinMaxType t1 t2)) -- | Compound type constraint useful for test definition. type CanMinMaxXX t1 t2 = (CanMinMaxX t1 t2, HasEqCertainly (MinMaxType t1 t2) (MinMaxType t2 t1)) -- | A replacement for Prelude's abs. If Num t, then one -- can use the default implementation to mirror Prelude's abs. class CanAbs t where type AbsType t type AbsType t = t abs = abs where { type family AbsType t; type AbsType t = t; } abs :: CanAbs t => t -> AbsType t abs :: (CanAbs t, AbsType t ~ t, Num t) => t -> t type CanAbsSameType t = (CanAbs t, AbsType t ~ t) -- | HSpec properties that each numeric implementation of CanNeg should -- satisfy. specCanNegNum :: (CanNegX t, CanNegX (NegType t), HasEqCertainly t (NegType (NegType t)), ConvertibleExactly Integer t, HasEqCertainly t t, HasEqCertainly t (NegType t), CanTestPosNeg t, CanTestPosNeg (NegType t)) => T t -> Spec -- | HSpec properties that each implementation of CanAbs should satisfy. specCanAbs :: (CanAbsX t, CanAbsX (AbsType t)) => T t -> Spec instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType GHC.Integer.Type.Integer b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType a0 GHC.Integer.Type.Integer), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType GHC.Types.Int b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType a0 GHC.Types.Int), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType GHC.Real.Rational b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType a0 GHC.Real.Rational), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType GHC.Types.Double b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.MinMaxAbs.MinMaxType a0 GHC.Types.Double), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance Numeric.MixedTypes.Bool.CanNeg GHC.Types.Int instance Numeric.MixedTypes.Bool.CanNeg GHC.Integer.Type.Integer instance Numeric.MixedTypes.Bool.CanNeg GHC.Real.Rational instance Numeric.MixedTypes.Bool.CanNeg GHC.Types.Double instance Numeric.MixedTypes.MinMaxAbs.CanAbs GHC.Types.Int instance Numeric.MixedTypes.MinMaxAbs.CanAbs GHC.Integer.Type.Integer instance Numeric.MixedTypes.MinMaxAbs.CanAbs GHC.Real.Rational instance Numeric.MixedTypes.MinMaxAbs.CanAbs GHC.Types.Double instance (Numeric.MixedTypes.MinMaxAbs.CanAbs a, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.MinMaxAbs.AbsType a), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.MinMaxAbs.CanAbs (Control.CollectErrors.CollectErrors es a) instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Double GHC.Types.Double instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric a b => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric [a] [b] instance Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric a b => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric (GHC.Base.Maybe a) (GHC.Base.Maybe b) instance (Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.MinMaxAbs.MinMaxType a b), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.MinMaxAbs.CanMinMaxAsymmetric (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) module Numeric.MixedTypes.AddSub type CanAdd t1 t2 = (CanAddAsymmetric t1 t2, CanAddAsymmetric t2 t1, AddType t1 t2 ~ AddType t2 t1) -- | A replacement for Prelude's +. If t1 = t2 and Num -- t1, then one can use the default implementation to mirror -- Prelude's +. class CanAddAsymmetric t1 t2 where type AddType t1 t2 type AddType t1 t2 = t1 add = (+) where { type family AddType t1 t2; type AddType t1 t2 = t1; } add :: CanAddAsymmetric t1 t2 => t1 -> t2 -> AddType t1 t2 add :: (CanAddAsymmetric t1 t2, AddType t1 t2 ~ t1, t1 ~ t2, Num t1) => t1 -> t1 -> t1 type CanAddThis t1 t2 = (CanAdd t1 t2, AddType t1 t2 ~ t1) type CanAddSameType t = CanAddThis t t (+) :: (CanAddAsymmetric t1 t2) => t1 -> t2 -> AddType t1 t2 infixl 6 + sum :: (CanAddSameType t, ConvertibleExactly Integer t) => [t] -> t -- | HSpec properties that each implementation of CanAdd should satisfy. specCanAdd :: (CanAddXX t1 t1, CanAddXX t1 t2, CanAddXX t1 t3, CanAddXX t2 t3, CanAddXX t1 (AddType t2 t3), CanAddXX (AddType t1 t2) t3, ConvertibleExactly Integer t1, CanTestPosNeg t1, HasEqCertainly (AddType t1 (AddType t2 t3)) (AddType (AddType t1 t2) t3)) => T t1 -> T t2 -> T t3 -> Spec -- | HSpec properties that each implementation of CanAdd should satisfy. specCanAddNotMixed :: (CanAddXX t t, CanAddXX t (AddType t t), ConvertibleExactly Integer t, CanTestPosNeg t) => T t -> Spec -- | HSpec properties that each implementation of CanAddSameType should -- satisfy. specCanAddSameType :: (ConvertibleExactly Integer t, Show t, HasEqCertainly t t, CanAddSameType t) => T t -> Spec -- | Compound type constraint useful for test definition. type CanAddX t1 t2 = (CanAdd t1 t2, Show t1, Arbitrary t1, Show t2, Arbitrary t2, Show (AddType t1 t2), HasEqCertainly t1 (AddType t1 t2), HasEqCertainly t2 (AddType t1 t2), HasEqCertainly (AddType t1 t2) (AddType t1 t2), HasOrderCertainly t1 (AddType t1 t2), HasOrderCertainly t2 (AddType t1 t2), HasOrderCertainly (AddType t1 t2) (AddType t1 t2)) -- | Compound type constraint useful for test definition. type CanAddXX t1 t2 = (CanAddX t1 t2, HasEqCertainly (AddType t1 t2) (AddType t2 t1)) -- | A replacement for Prelude's binary -. -- -- If CanNeg t2 and CanAdd t1 (NegType t2), then one -- can use the default implementation via a-b = a + (-b). class CanSub t1 t2 where type SubType t1 t2 type SubType t1 t2 = AddType t1 (NegType t2) a `sub` b = a + (negate b) where { type family SubType t1 t2; type SubType t1 t2 = AddType t1 (NegType t2); } sub :: CanSub t1 t2 => t1 -> t2 -> SubType t1 t2 sub :: (CanSub t1 t2, SubType t1 t2 ~ AddType t1 (NegType t2), CanNeg t2, CanAdd t1 (NegType t2)) => t1 -> t2 -> SubType t1 t2 type CanSubThis t1 t2 = (CanSub t1 t2, SubType t1 t2 ~ t1) type CanSubSameType t = CanSubThis t t (-) :: (CanSub t1 t2) => t1 -> t2 -> SubType t1 t2 infixl 6 - -- | HSpec properties that each implementation of CanSub should satisfy. specCanSub :: (CanSubX t1 t1, CanSubX t1 t2, CanNeg t2, CanAdd t1 (NegType t2), HasEqCertainly (SubType t1 t2) (AddType t1 (NegType t2)), Show (AddType t1 (NegType t2)), ConvertibleExactly Integer t1) => T t1 -> T t2 -> Spec -- | HSpec properties that each implementation of CanSub should satisfy. specCanSubNotMixed :: (CanSubX t t, CanSubX t (SubType t t), CanNeg t, CanAdd t (NegType t), Show (AddType t (NegType t)), HasEqCertainly (SubType t t) (AddType t (NegType t)), ConvertibleExactly Integer t) => T t -> Spec -- | Compound type constraint useful for test definition. type CanSubX t1 t2 = (CanSub t1 t2, HasEqCertainly t1 (SubType t1 t2), CanAddXX t1 t2, Show (SubType t1 t2)) instance (Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType GHC.Integer.Type.Integer b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanSub a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType a0 GHC.Integer.Type.Integer), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType GHC.Integer.Type.Integer b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType a0 GHC.Integer.Type.Integer), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType GHC.Types.Int b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanSub a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType a0 GHC.Types.Int), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType GHC.Types.Int b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType a0 GHC.Types.Int), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType GHC.Real.Rational b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanSub a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType a0 GHC.Real.Rational), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType GHC.Real.Rational b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType a0 GHC.Real.Rational), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType GHC.Types.Double b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanSub a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.SubType a0 GHC.Types.Double), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanSub (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType GHC.Types.Double b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.AddSub.AddType a0 GHC.Types.Double), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanAddAsymmetric a b => Numeric.MixedTypes.AddSub.CanAddAsymmetric [a] [b] instance Numeric.MixedTypes.AddSub.CanAddAsymmetric a b => Numeric.MixedTypes.AddSub.CanAddAsymmetric (GHC.Base.Maybe a) (GHC.Base.Maybe b) instance (Numeric.MixedTypes.AddSub.CanAddAsymmetric a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.AddSub.AddType a b), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanSub a b => Numeric.MixedTypes.AddSub.CanSub [a] [b] instance Numeric.MixedTypes.AddSub.CanSub a b => Numeric.MixedTypes.AddSub.CanSub (GHC.Base.Maybe a) (GHC.Base.Maybe b) instance (Numeric.MixedTypes.AddSub.CanSub a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.AddSub.SubType a b), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.AddSub.CanSub (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) module Numeric.MixedTypes.Round -- | A replacement for Prelude's RealFrac operations, such as round -- in which the result type is fixed to Integer. -- -- If RealFrac t and CanTestPosNeg t, then one can use -- the default implementation to mirror Prelude's round, etc. -- -- In other cases, it is sufficient to define properFraction. class CanRound t where properFraction = properFraction truncate = fst . properFraction round x | - 0.5 !! 0.5 = n + 1 | even n = n | r !! 0.0 = n + 1 | otherwise = error "round default defn: Bad value" where (n, r) = properFraction x ceiling x | isCertainlyPositive r = n + 1 | otherwise = n where (n, r) = properFraction x floor x | isCertainlyNegative r = n - 1 | otherwise = n where (n, r) = properFraction x properFraction :: CanRound t => t -> (Integer, t) properFraction :: (CanRound t, RealFrac t) => t -> (Integer, t) truncate :: CanRound t => t -> Integer round :: CanRound t => t -> Integer round :: (CanRound t, HasOrderCertainly t Rational) => t -> Integer ceiling :: CanRound t => t -> Integer ceiling :: (CanRound t, CanTestPosNeg t) => t -> Integer floor :: CanRound t => t -> Integer floor :: (CanRound t, CanTestPosNeg t) => t -> Integer class HasIntegerBounds t where integerBounds x = (floor x, ceiling x) integerBounds :: HasIntegerBounds t => t -> (Integer, Integer) integerBounds :: (HasIntegerBounds t, CanRound t) => t -> (Integer, Integer) -- | HSpec properties that each implementation of CanRound should satisfy. specCanRound :: (CanRoundX t, HasIntegers t) => T t -> Spec -- | HSpec properties that each implementation of CanRound should satisfy. specHasIntegerBounds :: (HasIntegerBoundsX t) => T t -> Spec instance Numeric.MixedTypes.Round.CanRound GHC.Real.Rational instance Numeric.MixedTypes.Round.CanRound GHC.Types.Double instance Numeric.MixedTypes.Round.HasIntegerBounds GHC.Real.Rational instance Numeric.MixedTypes.Round.HasIntegerBounds GHC.Types.Double instance Numeric.MixedTypes.Round.HasIntegerBounds GHC.Integer.Type.Integer instance Numeric.MixedTypes.Round.HasIntegerBounds GHC.Types.Int module Numeric.MixedTypes.Ring type CanAddSubMulBy t s = (CanAddThis t s, CanSubThis t s, CanMulBy t s) type Ring t = (CanNegSameType t, CanAddSameType t, CanSubSameType t, CanMulSameType t, CanPowCNBy t Integer, CanPowCNBy t Int, HasEq t t, HasEq t Integer, CanAddSubMulBy t Integer, HasEq t Int, CanAddSubMulBy t Int, HasIntegers t) type CertainlyEqRing t = (Ring t, HasEqCertainly t t, HasEqCertainly t Int, HasEqCertainly t Integer) type OrderedRing t = (Ring t, HasOrder t t, HasOrder t Int, HasOrder t Integer) type OrderedCertainlyRing t = (CertainlyEqRing t, HasOrderCertainly t t, HasOrderCertainly t Int, HasOrderCertainly t Integer, CanTestPosNeg t) type CanMul t1 t2 = (CanMulAsymmetric t1 t2, CanMulAsymmetric t2 t1, MulType t1 t2 ~ MulType t2 t1) -- | A replacement for Prelude's *. If t1 = t2 and Num -- t1, then one can use the default implementation to mirror -- Prelude's *. class CanMulAsymmetric t1 t2 where type MulType t1 t2 type MulType t1 t2 = t1 mul = (*) where { type family MulType t1 t2; type MulType t1 t2 = t1; } mul :: CanMulAsymmetric t1 t2 => t1 -> t2 -> MulType t1 t2 mul :: (CanMulAsymmetric t1 t2, MulType t1 t2 ~ t1, t1 ~ t2, Num t1) => t1 -> t1 -> t1 type CanMulBy t1 t2 = (CanMul t1 t2, MulType t1 t2 ~ t1) type CanMulSameType t = CanMulBy t t (*) :: (CanMulAsymmetric t1 t2) => t1 -> t2 -> MulType t1 t2 infixl 7 * product :: (CanMulSameType t, ConvertibleExactly Integer t) => [t] -> t -- | HSpec properties that each implementation of CanMul should satisfy. specCanMul :: (CanMulX t1 t2, CanMulX t1 t3, CanMulX t2 t3, CanMulX t1 (MulType t2 t3), CanMulX (MulType t1 t2) t3, HasEqCertainly (MulType t1 (MulType t2 t3)) (MulType (MulType t1 t2) t3), CanAdd t2 t3, CanMulX t1 (AddType t2 t3), CanAddX (MulType t1 t2) (MulType t1 t3), HasEqCertainly (MulType t1 (AddType t2 t3)) (AddType (MulType t1 t2) (MulType t1 t3)), ConvertibleExactly Integer t2) => T t1 -> T t2 -> T t3 -> Spec -- | HSpec properties that each implementation of CanMul should satisfy. specCanMulNotMixed :: (CanMulX t t, CanMulX t (MulType t t), HasEqCertainly (MulType (MulType t t) t) (MulType t (MulType t t)), CanAdd t t, CanMulX t (AddType t t), CanAddX (MulType t t) (MulType t t), HasEqCertainly (MulType t (AddType t t)) (AddType (MulType t t) (MulType t t)), ConvertibleExactly Integer t) => T t -> Spec -- | HSpec properties that each implementation of CanMulSameType should -- satisfy. specCanMulSameType :: (ConvertibleExactly Integer t, Show t, HasEqCertainly t t, CanMulSameType t) => T t -> Spec -- | Compound type constraint useful for test definition. type CanMulX t1 t2 = (CanMul t1 t2, Show t1, Arbitrary t1, Show t2, Arbitrary t2, Show (MulType t1 t2), HasEqCertainly t1 (MulType t1 t2), HasEqCertainly t2 (MulType t1 t2), HasEqCertainly (MulType t1 t2) (MulType t1 t2), HasOrderCertainly t1 (MulType t1 t2), HasOrderCertainly t2 (MulType t1 t2), HasOrderCertainly (MulType t1 t2) (MulType t1 t2)) -- | A replacement for Prelude's binary ^ and ^^. If Num -- t1 and Integral t2, then one can use the default -- implementation to mirror Prelude's ^. class CanPow t1 t2 where type PowType t1 t2 type PowType t1 t2 = t1 where { type family PowType t1 t2; type PowType t1 t2 = t1; } pow :: CanPow t1 t2 => t1 -> t2 -> PowType t1 t2 type CanPowBy t1 t2 = (CanPow t1 t2, PowType t1 t2 ~ t1) type CanPowCNBy t1 t2 = (CanPow t1 t2, PowType t1 t2 ~ EnsureCN t1) (^) :: (CanPow t1 t2) => t1 -> t2 -> PowType t1 t2 infixl 8 ^ -- | Like ^ but throwing an exception if the power is undefined. (^!) :: (CanPow t1 t2, Show (PowType t1 t2), CanEnsureCN (PowType t1 t2)) => t1 -> t2 -> EnsureNoCN (PowType t1 t2) infixl 8 ^! powUsingMul :: (CanBeInteger e, CanMulSameType t, HasIntegers t) => t -> e -> t -- | HSpec properties that each implementation of CanPow should satisfy. specCanPow :: (CanPowX t1 t2, HasEqCertainly t1 (PowType t1 t2), ConvertibleExactly Integer t1, ConvertibleExactly Integer t2, CanTestPosNeg t2, CanAdd t2 Integer, CanMulX t1 (PowType t1 t2), CanPowX t1 (AddType t2 Integer), HasEqCertainly (MulType t1 (PowType t1 t2)) (PowType t1 (AddType t2 Integer))) => T t1 -> T t2 -> Spec -- | Compound type constraint useful for test definition. type CanPowX t1 t2 = (CanPow t1 t2, Show t1, Arbitrary t1, Show t2, Arbitrary t2, Show (PowType t1 t2)) instance (Numeric.MixedTypes.Ring.CanPow GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType GHC.Integer.Type.Integer b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanPow a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType a0 GHC.Integer.Type.Integer), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType GHC.Integer.Type.Integer b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType a0 GHC.Integer.Type.Integer), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.Ring.CanPow GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType GHC.Types.Int b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanPow a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType a0 GHC.Types.Int), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType GHC.Types.Int b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType a0 GHC.Types.Int), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.Ring.CanPow GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType GHC.Real.Rational b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanPow a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType a0 GHC.Real.Rational), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType GHC.Real.Rational b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType a0 GHC.Real.Rational), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.Ring.CanPow GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType GHC.Types.Double b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanPow a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.PowType a0 GHC.Types.Double), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanPow (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType GHC.Types.Double b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Ring.MulType a0 GHC.Types.Double), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Ring.CanMulAsymmetric (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double GHC.Types.Double instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double GHC.Types.Int instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational GHC.Types.Double instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double GHC.Real.Rational instance Numeric.MixedTypes.Ring.CanMulAsymmetric a b => Numeric.MixedTypes.Ring.CanMulAsymmetric [a] [b] instance Numeric.MixedTypes.Ring.CanMulAsymmetric a b => Numeric.MixedTypes.Ring.CanMulAsymmetric (GHC.Base.Maybe a) (GHC.Base.Maybe b) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Ring.MulType a b), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Ring.CanMulAsymmetric (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) instance Numeric.MixedTypes.Ring.CanPow GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanPow GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.Ring.CanPow GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanPow GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.Ring.CanPow GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.Ring.CanPow GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanPow GHC.Types.Double GHC.Types.Int instance Numeric.MixedTypes.Ring.CanPow GHC.Types.Double GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanPow a b => Numeric.MixedTypes.Ring.CanPow (GHC.Base.Maybe a) (GHC.Base.Maybe b) instance (Numeric.MixedTypes.Ring.CanPow a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Ring.PowType a b), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Ring.CanPow (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) module Numeric.MixedTypes.Field type CanAddSubMulDivCNBy t s = (CanAddSubMulBy t s, CanDivCNBy t s) type Field t = (FieldPre t, CanEnsureCN t, FieldPre (EnsureCN t)) type CertainlyEqField t = (CertainlyEqFieldPre t, CanEnsureCN t, CertainlyEqFieldPre (EnsureCN t)) type OrderedField t = (OrderedFieldPre t, CanEnsureCN t, OrderedFieldPre (EnsureCN t)) type OrderedCertainlyField t = (OrderedCertainlyFieldPre t, CanEnsureCN t, OrderedCertainlyFieldPre (EnsureCN t)) -- | A replacement for Prelude's binary /. If t1 = t2 and -- Fractional t1, then one can use the default implementation to -- mirror Prelude's /. class CanDiv t1 t2 where type DivTypeNoCN t1 t2 type DivType t1 t2 type DivType t1 t2 = EnsureCN (DivTypeNoCN t1 t2) divide = divideCN divideNoCN where { type family DivTypeNoCN t1 t2; type family DivType t1 t2; type DivType t1 t2 = EnsureCN (DivTypeNoCN t1 t2); } divideNoCN :: CanDiv t1 t2 => t1 -> t2 -> DivTypeNoCN t1 t2 divide :: CanDiv t1 t2 => t1 -> t2 -> DivType t1 t2 divide :: (CanDiv t1 t2, CanTestZero t2, CanEnsureCN (DivTypeNoCN t1 t2)) => t1 -> t2 -> EnsureCN (DivTypeNoCN t1 t2) type CanDivBy t1 t2 = (CanDiv t1 t2, DivType t1 t2 ~ t1) type CanDivCNBy t1 t2 = (CanDiv t1 t2, DivType t1 t2 ~ EnsureCN t1) type CanDivSameType t = CanDivBy t t type CanDivCNSameType t = CanDivCNBy t t type CanRecip t = CanDiv Integer t type CanRecipSameType t = (CanDiv Integer t, DivType Integer t ~ t) type CanRecipCNSameType t = (CanDiv Integer t, DivType Integer t ~ EnsureCN t) (/) :: (CanDiv t1 t2) => t1 -> t2 -> DivType t1 t2 infixl 7 / (/!) :: (CanDiv t1 t2) => t1 -> t2 -> DivTypeNoCN t1 t2 infixl 7 /! recip :: (CanRecip t) => t -> DivType Integer t powUsingMulRecip :: (CanBeInteger e, HasIntegers t, CanRecipCNSameType t, CanMulSameType t, CanEnsureCN t) => t -> e -> EnsureCN t -- | HSpec properties that each implementation of CanDiv should satisfy. specCanDiv :: (CanRecip t1, CanRecip (DivType Integer t1), Show (DivType Integer (DivType Integer t1)), HasEqCertainly t1 (DivType Integer (DivType Integer t1)), CanTestZero (DivType Integer t1), CanDivX t1 t2, CanTestZero t1, CanTestZero t2, CanDivX t1 t1, CanMulX t1 (DivType t1 t2), ConvertibleExactly Integer t2, ConvertibleExactly Integer t1) => T t1 -> T t2 -> Spec -- | HSpec properties that each implementation of CanDiv should satisfy. specCanDivNotMixed :: (CanRecip t, CanRecip (DivType Integer t), Show (DivType Integer (DivType Integer t)), HasEqCertainly t (DivType Integer (DivType Integer t)), CanTestZero (DivType Integer t), CanDivX t t, CanTestZero t, CanMulX t (DivType t t), ConvertibleExactly Integer t) => T t -> Spec -- | Compound type constraint useful for test definition. type CanDivX t1 t2 = (CanDiv t1 t2, Show t1, Arbitrary t1, Show t2, Arbitrary t2, Show (DivType t1 t2), HasEqCertainly t1 (DivType t1 t2)) instance (Numeric.MixedTypes.Field.CanDiv GHC.Integer.Type.Integer b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType GHC.Integer.Type.Integer b0), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN GHC.Integer.Type.Integer b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv GHC.Integer.Type.Integer (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Field.CanDiv a0 GHC.Integer.Type.Integer, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType a0 GHC.Integer.Type.Integer), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN a0 GHC.Integer.Type.Integer), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv (Control.CollectErrors.CollectErrors es0 a0) GHC.Integer.Type.Integer instance (Numeric.MixedTypes.Field.CanDiv GHC.Types.Int b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType GHC.Types.Int b0), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN GHC.Types.Int b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv GHC.Types.Int (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Field.CanDiv a0 GHC.Types.Int, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType a0 GHC.Types.Int), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN a0 GHC.Types.Int), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Int instance (Numeric.MixedTypes.Field.CanDiv GHC.Real.Rational b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType GHC.Real.Rational b0), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN GHC.Real.Rational b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv GHC.Real.Rational (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Field.CanDiv a0 GHC.Real.Rational, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType a0 GHC.Real.Rational), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN a0 GHC.Real.Rational), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv (Control.CollectErrors.CollectErrors es0 a0) GHC.Real.Rational instance (Numeric.MixedTypes.Field.CanDiv GHC.Types.Double b0, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType GHC.Types.Double b0), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN GHC.Types.Double b0), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv GHC.Types.Double (Control.CollectErrors.CollectErrors es0 b0) instance (Numeric.MixedTypes.Field.CanDiv a0 GHC.Types.Double, Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivType a0 GHC.Types.Double), Control.CollectErrors.CanEnsureCE es0 (Numeric.MixedTypes.Field.DivTypeNoCN a0 GHC.Types.Double), Control.CollectErrors.SuitableForCE es0) => Numeric.MixedTypes.Field.CanDiv (Control.CollectErrors.CollectErrors es0 a0) GHC.Types.Double instance Numeric.MixedTypes.Field.CanDiv GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Double GHC.Integer.Type.Integer instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Double GHC.Types.Int instance Numeric.MixedTypes.Field.CanDiv GHC.Real.Rational GHC.Types.Double instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Double GHC.Real.Rational instance Numeric.MixedTypes.Field.CanDiv a b => Numeric.MixedTypes.Field.CanDiv [a] [b] instance Numeric.MixedTypes.Field.CanDiv a b => Numeric.MixedTypes.Field.CanDiv (GHC.Base.Maybe a) (GHC.Base.Maybe b) instance (Numeric.MixedTypes.Field.CanDiv a b, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Field.DivType a b), Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Field.DivTypeNoCN a b), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Field.CanDiv (Control.CollectErrors.CollectErrors es a) (Control.CollectErrors.CollectErrors es b) instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Int GHC.Types.Int instance Numeric.MixedTypes.Field.CanDiv GHC.Integer.Type.Integer GHC.Integer.Type.Integer instance Numeric.MixedTypes.Field.CanDiv GHC.Real.Rational GHC.Real.Rational instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Int GHC.Integer.Type.Integer instance Numeric.MixedTypes.Field.CanDiv GHC.Integer.Type.Integer GHC.Types.Int instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Int GHC.Real.Rational instance Numeric.MixedTypes.Field.CanDiv GHC.Real.Rational GHC.Types.Int instance Numeric.MixedTypes.Field.CanDiv GHC.Integer.Type.Integer GHC.Real.Rational instance Numeric.MixedTypes.Field.CanDiv GHC.Real.Rational GHC.Integer.Type.Integer instance Numeric.MixedTypes.Field.CanDiv GHC.Types.Double GHC.Types.Double module Numeric.MixedTypes.Elementary -- | A replacement for Prelude's sqrt. If Floating t, then -- one can use the default implementation to mirror Prelude's -- sqrt. class CanSqrt t where type SqrtType t type SqrtType t = t sqrt = sqrt where { type family SqrtType t; type SqrtType t = t; } sqrt :: CanSqrt t => t -> SqrtType t sqrt :: (CanSqrt t, SqrtType t ~ t, Floating t) => t -> t type CanSqrtSameType t = (CanSqrt t, SqrtType t ~ t) type CanSqrtCNSameType t = (CanSqrt t, SqrtType t ~ EnsureCN t) -- | HSpec properties that each implementation of CanSqrt should satisfy. specCanSqrtReal :: (CanSqrtX t, CanPowX (SqrtType t) Integer, HasEqCertainly t (PowType (SqrtType t) Integer)) => T t -> Spec -- | A replacement for Prelude's exp. If Floating t, then -- one can use the default implementation to mirror Prelude's -- exp. class CanExp t where type ExpType t type ExpType t = t exp = exp where { type family ExpType t; type ExpType t = t; } exp :: CanExp t => t -> ExpType t exp :: (CanExp t, ExpType t ~ t, Floating t) => t -> t type CanExpSameType t = (CanExp t, ExpType t ~ t) -- | HSpec properties that each implementation of CanExp should satisfy. specCanExpReal :: (CanExpX t) => T t -> Spec -- | A replacement for Prelude's log. If Floating t, then -- one can use the default implementation to mirror Prelude's -- log. class CanLog t where type LogType t type LogType t = t log = log where { type family LogType t; type LogType t = t; } log :: CanLog t => t -> LogType t log :: (CanLog t, LogType t ~ t, Floating t) => t -> t type CanLogSameType t = (CanLog t, LogType t ~ t) type CanLogCNSameType t = (CanLog t, LogType t ~ EnsureCN t) -- | HSpec properties that each implementation of CanLog should satisfy. specCanLogReal :: (CanLogX t, CanLogX (DivType Integer t), CanExp t, CanLogX (ExpType t), HasEqCertainly (LogType t) (LogType (EnsureCN t)), HasEqCertainlyCN t (LogType (ExpType t))) => T t -> Spec powUsingExpLog :: (CanTestPosNeg t, CanEnsureCN t, CanEnsureCN (EnsureCN t), EnsureCN t ~ EnsureCN (EnsureCN t), CanLogCNSameType t, CanMulSameType t, CanMulSameType (EnsureCN t), CanExpSameType (EnsureCN t), CanTestInteger t, HasIntegers t, CanTestZero t, CanRecipCNSameType t, HasIntegers (EnsureCN t)) => t -> t -> EnsureCN t -- | A replacement for Prelude's cos and sin. If Floating -- t, then one can use the default implementation to mirror -- Prelude's sin, cos. class CanSinCos t where type SinCosType t type SinCosType t = t cos = cos sin = sin where { type family SinCosType t; type SinCosType t = t; } cos :: CanSinCos t => t -> SinCosType t cos :: (CanSinCos t, SinCosType t ~ t, Floating t) => t -> t sin :: CanSinCos t => t -> SinCosType t sin :: (CanSinCos t, SinCosType t ~ t, Floating t) => t -> t type CanSinCosSameType t = (CanSinCos t, SinCosType t ~ t) -- | HSpec properties that each implementation of CanSinCos should satisfy. -- -- Derived partially from -- http://math.stackexchange.com/questions/1303044/axiomatic-definition-of-sin-and-cos specCanSinCosReal :: (CanSinCosX t) => T t -> Spec -- | Approximate pi, synonym for Prelude's pi. -- -- We do not define (exect) pi in this package as we have no -- type that can represent it exactly. approxPi :: (Floating t) => t instance Numeric.MixedTypes.Elementary.CanSqrt GHC.Types.Double instance (Numeric.MixedTypes.Elementary.CanSqrt a, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Elementary.SqrtType a), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Elementary.CanSqrt (Control.CollectErrors.CollectErrors es a) instance Numeric.MixedTypes.Elementary.CanExp GHC.Types.Double instance (Numeric.MixedTypes.Elementary.CanExp a, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Elementary.ExpType a), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Elementary.CanExp (Control.CollectErrors.CollectErrors es a) instance Numeric.MixedTypes.Elementary.CanLog GHC.Types.Double instance (Numeric.MixedTypes.Elementary.CanLog a, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Elementary.LogType a), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Elementary.CanLog (Control.CollectErrors.CollectErrors es a) instance Numeric.MixedTypes.Ring.CanPow GHC.Types.Double GHC.Types.Double instance Numeric.MixedTypes.Ring.CanPow GHC.Types.Double GHC.Real.Rational instance Numeric.MixedTypes.Ring.CanPow GHC.Real.Rational GHC.Types.Double instance Numeric.MixedTypes.Ring.CanPow GHC.Integer.Type.Integer GHC.Types.Double instance Numeric.MixedTypes.Ring.CanPow GHC.Types.Int GHC.Types.Double instance Numeric.MixedTypes.Elementary.CanSinCos GHC.Types.Double instance (Numeric.MixedTypes.Elementary.CanSinCos a, Control.CollectErrors.CanEnsureCE es (Numeric.MixedTypes.Elementary.SinCosType a), Control.CollectErrors.SuitableForCE es) => Numeric.MixedTypes.Elementary.CanSinCos (Control.CollectErrors.CollectErrors es a) -- | Instances for Data.Complex. module Numeric.MixedTypes.Complex instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer t => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Integer.Type.Integer (Data.Complex.Complex t) instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int t => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Types.Int (Data.Complex.Complex t) instance Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Real.Rational t => Numeric.MixedTypes.Literals.ConvertibleExactly GHC.Real.Rational (Data.Complex.Complex t) instance Numeric.MixedTypes.Literals.ConvertibleExactly t1 t2 => Numeric.MixedTypes.Literals.ConvertibleExactly (Data.Complex.Complex t1) (Data.Complex.Complex t2) instance Numeric.MixedTypes.Eq.HasEqAsymmetric a b => Numeric.MixedTypes.Eq.HasEqAsymmetric (Data.Complex.Complex a) (Data.Complex.Complex b) instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer b => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Integer.Type.Integer (Data.Complex.Complex b) instance Numeric.MixedTypes.Eq.HasEqAsymmetric a GHC.Integer.Type.Integer => Numeric.MixedTypes.Eq.HasEqAsymmetric (Data.Complex.Complex a) GHC.Integer.Type.Integer instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Real.Rational b => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Real.Rational (Data.Complex.Complex b) instance Numeric.MixedTypes.Eq.HasEqAsymmetric a GHC.Real.Rational => Numeric.MixedTypes.Eq.HasEqAsymmetric (Data.Complex.Complex a) GHC.Real.Rational instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int b => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Int (Data.Complex.Complex b) instance Numeric.MixedTypes.Eq.HasEqAsymmetric a GHC.Types.Int => Numeric.MixedTypes.Eq.HasEqAsymmetric (Data.Complex.Complex a) GHC.Types.Int instance Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Double b => Numeric.MixedTypes.Eq.HasEqAsymmetric GHC.Types.Double (Data.Complex.Complex b) instance Numeric.MixedTypes.Eq.HasEqAsymmetric a GHC.Types.Double => Numeric.MixedTypes.Eq.HasEqAsymmetric (Data.Complex.Complex a) GHC.Types.Double instance (Numeric.MixedTypes.Eq.CanTestInteger t, Numeric.MixedTypes.Eq.CanTestZero t) => Numeric.MixedTypes.Eq.CanTestInteger (Data.Complex.Complex t) instance Numeric.MixedTypes.Bool.CanNeg t => Numeric.MixedTypes.Bool.CanNeg (Data.Complex.Complex t) instance Numeric.MixedTypes.AddSub.CanAddAsymmetric a b => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Data.Complex.Complex a) (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer b => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Integer.Type.Integer (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanAddAsymmetric a GHC.Integer.Type.Integer => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Data.Complex.Complex a) GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational b => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Real.Rational (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanAddAsymmetric a GHC.Real.Rational => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Data.Complex.Complex a) GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int b => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Int (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanAddAsymmetric a GHC.Types.Int => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Data.Complex.Complex a) GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double b => Numeric.MixedTypes.AddSub.CanAddAsymmetric GHC.Types.Double (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanAddAsymmetric a GHC.Types.Double => Numeric.MixedTypes.AddSub.CanAddAsymmetric (Data.Complex.Complex a) GHC.Types.Double instance Numeric.MixedTypes.AddSub.CanSub a b => Numeric.MixedTypes.AddSub.CanSub (Data.Complex.Complex a) (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer b => Numeric.MixedTypes.AddSub.CanSub GHC.Integer.Type.Integer (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanSub a GHC.Integer.Type.Integer => Numeric.MixedTypes.AddSub.CanSub (Data.Complex.Complex a) GHC.Integer.Type.Integer instance Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational b => Numeric.MixedTypes.AddSub.CanSub GHC.Real.Rational (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanSub a GHC.Real.Rational => Numeric.MixedTypes.AddSub.CanSub (Data.Complex.Complex a) GHC.Real.Rational instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int b => Numeric.MixedTypes.AddSub.CanSub GHC.Types.Int (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanSub a GHC.Types.Int => Numeric.MixedTypes.AddSub.CanSub (Data.Complex.Complex a) GHC.Types.Int instance Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double b => Numeric.MixedTypes.AddSub.CanSub GHC.Types.Double (Data.Complex.Complex b) instance Numeric.MixedTypes.AddSub.CanSub a GHC.Types.Double => Numeric.MixedTypes.AddSub.CanSub (Data.Complex.Complex a) GHC.Types.Double instance (Numeric.MixedTypes.Ring.CanMulAsymmetric a b, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType a b), Numeric.MixedTypes.AddSub.CanSubSameType (Numeric.MixedTypes.Ring.MulType a b)) => Numeric.MixedTypes.Ring.CanMulAsymmetric (Data.Complex.Complex a) (Data.Complex.Complex b) instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer b => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer (Data.Complex.Complex b) instance Numeric.MixedTypes.Ring.CanMulAsymmetric a GHC.Integer.Type.Integer => Numeric.MixedTypes.Ring.CanMulAsymmetric (Data.Complex.Complex a) GHC.Integer.Type.Integer instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int b => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int (Data.Complex.Complex b) instance Numeric.MixedTypes.Ring.CanMulAsymmetric a GHC.Types.Int => Numeric.MixedTypes.Ring.CanMulAsymmetric (Data.Complex.Complex a) GHC.Types.Int instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational b => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational (Data.Complex.Complex b) instance Numeric.MixedTypes.Ring.CanMulAsymmetric a GHC.Real.Rational => Numeric.MixedTypes.Ring.CanMulAsymmetric (Data.Complex.Complex a) GHC.Real.Rational instance Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double b => Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double (Data.Complex.Complex b) instance Numeric.MixedTypes.Ring.CanMulAsymmetric a GHC.Types.Double => Numeric.MixedTypes.Ring.CanMulAsymmetric (Data.Complex.Complex a) GHC.Types.Double instance (Numeric.MixedTypes.Ring.CanMulAsymmetric a b, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType a b), Numeric.MixedTypes.AddSub.CanSubSameType (Numeric.MixedTypes.Ring.MulType a b), Numeric.MixedTypes.Ring.CanMulAsymmetric b b, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType b b), Numeric.MixedTypes.Field.CanDiv (Numeric.MixedTypes.Ring.MulType a b) (Numeric.MixedTypes.Ring.MulType b b)) => Numeric.MixedTypes.Field.CanDiv (Data.Complex.Complex a) (Data.Complex.Complex b) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Integer.Type.Integer b, Numeric.MixedTypes.Ring.CanMulAsymmetric b b, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType b b), Numeric.MixedTypes.Field.CanDiv (Numeric.MixedTypes.Ring.MulType GHC.Integer.Type.Integer b) (Numeric.MixedTypes.Ring.MulType b b)) => Numeric.MixedTypes.Field.CanDiv GHC.Integer.Type.Integer (Data.Complex.Complex b) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Real.Rational b, Numeric.MixedTypes.Ring.CanMulAsymmetric b b, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType b b), Numeric.MixedTypes.Field.CanDiv (Numeric.MixedTypes.Ring.MulType GHC.Real.Rational b) (Numeric.MixedTypes.Ring.MulType b b)) => Numeric.MixedTypes.Field.CanDiv GHC.Real.Rational (Data.Complex.Complex b) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Int b, Numeric.MixedTypes.Ring.CanMulAsymmetric b b, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType b b), Numeric.MixedTypes.Field.CanDiv (Numeric.MixedTypes.Ring.MulType GHC.Types.Int b) (Numeric.MixedTypes.Ring.MulType b b)) => Numeric.MixedTypes.Field.CanDiv GHC.Types.Int (Data.Complex.Complex b) instance (Numeric.MixedTypes.Ring.CanMulAsymmetric GHC.Types.Double b, Numeric.MixedTypes.Ring.CanMulAsymmetric b b, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType b b), Numeric.MixedTypes.Field.CanDiv (Numeric.MixedTypes.Ring.MulType GHC.Types.Double b) (Numeric.MixedTypes.Ring.MulType b b)) => Numeric.MixedTypes.Field.CanDiv GHC.Types.Double (Data.Complex.Complex b) instance Numeric.MixedTypes.Field.CanDiv a GHC.Integer.Type.Integer => Numeric.MixedTypes.Field.CanDiv (Data.Complex.Complex a) GHC.Integer.Type.Integer instance Numeric.MixedTypes.Field.CanDiv a GHC.Types.Int => Numeric.MixedTypes.Field.CanDiv (Data.Complex.Complex a) GHC.Types.Int instance Numeric.MixedTypes.Field.CanDiv a GHC.Real.Rational => Numeric.MixedTypes.Field.CanDiv (Data.Complex.Complex a) GHC.Real.Rational instance Numeric.MixedTypes.Field.CanDiv a GHC.Types.Double => Numeric.MixedTypes.Field.CanDiv (Data.Complex.Complex a) GHC.Types.Double instance (Numeric.MixedTypes.Ring.CanMulAsymmetric t t, Numeric.MixedTypes.AddSub.CanAddSameType (Numeric.MixedTypes.Ring.MulType t t), Numeric.MixedTypes.Elementary.CanSqrt (Numeric.MixedTypes.Ring.MulType t t)) => Numeric.MixedTypes.MinMaxAbs.CanAbs (Data.Complex.Complex t) instance (Numeric.MixedTypes.Elementary.CanExp t, Numeric.MixedTypes.Elementary.CanSinCos t, Numeric.MixedTypes.Ring.CanMulAsymmetric (Numeric.MixedTypes.Elementary.ExpType t) (Numeric.MixedTypes.Elementary.SinCosType t)) => Numeric.MixedTypes.Elementary.CanExp (Data.Complex.Complex t) -- |

Main purpose

-- -- This package provides a version of Prelude where unary and binary -- operations such as not, +, == have their -- result type derived from the parameter type(s), allowing, e.g.: -- -- -- --
--   >>> :t let n = 1 :: Integer in n/(n+1)
--   CN Rational
--   
-- --
--   >>> :t 1/2
--   CN Rational
--   
-- -- (Integer literals are always of type Integer, not Num t -- => t.) -- -- -- --
--   >>> :t (length [x])+1/3
--   CN Rational
--   
-- -- The CN monad is required because integer division can, in -- general, fail as it is a partial operation: -- --
--   >>> 1/0
--   {[(ERROR,division by 0)]}
--   
-- -- Note that when evaluating 1/0, it evaluates to the error -- value printed above. This is not an exception, but a special value. -- -- When one is certain the division is well defined, one can remove -- CN in several ways: -- --
--   >>> :t (1%2)  -- using Data.Ratio.(%), works only for integers
--   Rational
--   
-- --
--   >>> :t (1/!2)  -- this works for non-integer division too
--   Rational
--   
-- --
--   >>> :t (~!) (1/2) -- ~! removes CN from any type
--   Rational
--   
-- -- The operator (/!) stands for division which throws an exception is the -- denominator is 0. It "propagates" any potential errors from the -- sub-expressions: -- --
--   >>> :t 1/!(1 - 1/n)
--   CN Rational
--   
-- -- The last example will throw an error exception when evaluated with -- n=1 but it will not thrown any excetion when n=0 -- -- -- --
--   >>> :t 2^2
--   CN Integer
--   
-- --
--   >>> :t 2.0^(-2)
--   CN Rational
--   
-- --
--   >>> :t (double 2)^(1/!2)
--   Double
--   
-- -- The following examples require package aern2-real: -- --
--   >>> :t 2^(1/2)
--   CauchyRealCN
--   
-- --
--   >>> :t pi
--   CauchyReal
--   
-- --
--   >>> :t sqrt 2
--   CauchyRealCN
--   
-- -- -- --
--   if x < 0 then -x else x
--   
--   
-- -- In the last example, if is overloaded so that it works for -- conditions of other types than Bool. Here the condition has -- the type Sequence (Maybe Bool). The whole expression is the -- sequence of balls in which those balls for which the condition is -- inconclusive are the union of the balls computed by both branches. -- --

Type classes

-- -- Arithmetic operations are provided via multi-parameter type classes -- and the result type is given by associated type families. For example: -- --
--   (+) :: (CanAddAsymmetric t1 t2) => t1 -> t2 -> AddType t1 t2
--   
--   
-- -- The type constraint CanAdd t1 t2 implies both -- CanAddAsymmetric t1 t2 and CanAddAsymmetric t2 t1. -- -- For convenience there are other aggregate type constraints such as -- CanAddThis t1 t2, which implies that the result is of type -- t1, and CanAddSameType t, which is a shortcut for -- CanAddThis t t. -- --

Testable specification

-- -- The arithmetic type classes are accompanied by generic hspec test -- suites, which are specialised to concrete instance types for their -- testing. These test suites include the expected algebraic properties -- of operations, such as commutativity and associativity of addition. -- --

Limitations

-- -- -- -- -- --
--   f: (CanMulAsymmetric t1 t2, CanAddAsymmetric t4 (MulType t1 t2),
--       CanAddAsymmetric (AddType t4 (MulType t1 t2)) Integer,
--       CanSqrt (AddType (AddType t4 (MulType t1 t2)) Integer)) =>
--      t4
--      -> t1
--      -> t2
--      -> SqrtType (AddType (AddType t4 (MulType t1 t2)) Integer)
--   
--   
-- -- -- --

Origin

-- -- The idea of having numeric expressions in Haskell with types derived -- bottom-up was initially suggested and implemented by Pieter Collins. -- This version is a fresh rewrite by Michal Konečný. -- --

More details

-- -- This module facilitates a single-line import for the package -- mixed-types-num. See the re-exported modules for further details. module MixedTypesNumPrelude -- | Forms the ratio of two integral numbers. (%) :: Integral a => a -> a -> Ratio a infixl 7 %