License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
Compared to the Haskell hierarchy of number classes this provide a more flexible approach that is closer to the mathematical foundation (group, field, etc)
This try to only provide one feature per class, at the expense of the number of classes.
Synopsis
- class (Integral a, Eq a, Ord a) => IsIntegral a where
- class IsIntegral a => IsNatural a where
- class Signed a where
- class Additive a where
- class Subtractive a where
- type Difference a
- (-) :: a -> a -> Difference a
- class Multiplicative a where
- class (Additive a, Multiplicative a) => IDivisible a where
- class Multiplicative a => Divisible a where
- (/) :: a -> a -> a
- data Sign
- recip :: Divisible a => a -> a
- class IntegralRounding a where
- roundUp :: Integral n => a -> n
- roundDown :: Integral n => a -> n
- roundTruncate :: Integral n => a -> n
- roundNearest :: Integral n => a -> n
- class FloatingPoint a where
- floatRadix :: Proxy a -> Integer
- floatDigits :: Proxy a -> Int
- floatRange :: Proxy a -> (Int, Int)
- floatDecode :: a -> (Integer, Int)
- floatEncode :: Integer -> Int -> a
Documentation
class (Integral a, Eq a, Ord a) => IsIntegral a where Source #
Number literals, convertible through the generic Integer type.
all number are Enum'erable, meaning that you can move to next element
Instances
class IsIntegral a => IsNatural a where Source #
Non Negative Number literals, convertible through the generic Natural type
Instances
types that have sign and can be made absolute
class Additive a where Source #
Represent class of things that can be added together, contains a neutral element and is commutative.
x + azero = x azero + x = x x + y = y + x
Instances
class Subtractive a where Source #
Represent class of things that can be subtracted.
Note that the result is not necessary of the same type as the operand depending on the actual type.
For example:
(-) :: Int -> Int -> Int (-) :: DateTime -> DateTime -> Seconds (-) :: Ptr a -> Ptr a -> PtrDiff (-) :: Natural -> Natural -> Maybe Natural
type Difference a Source #
(-) :: a -> a -> Difference a infixl 6 Source #
Instances
class Multiplicative a where Source #
Represent class of things that can be multiplied together
x * midentity = x midentity * x = x
Identity element over multiplication
(*) :: a -> a -> a infixl 7 Source #
Multiplication of 2 elements that result in another element
(^) :: (IsNatural n, Enum n, IDivisible n) => a -> n -> a infixr 8 Source #
Raise to power, repeated multiplication e.g. > a ^ 2 = a * a > a ^ 10 = (a ^ 5) * (a ^ 5) .. (^) :: (IsNatural n) => a -> n -> a
Instances
class (Additive a, Multiplicative a) => IDivisible a where Source #
Represent types that supports an euclidian division
(x ‘div‘ y) * y + (x ‘mod‘ y) == x
Instances
class Multiplicative a => Divisible a where Source #
Support for division between same types
This is likely to change to represent specific mathematic divisions
Sign of a signed number
class IntegralRounding a where Source #
roundUp :: Integral n => a -> n Source #
Round up, to the next integral.
Also known as ceiling
roundDown :: Integral n => a -> n Source #
Round down, to the previous integral
Also known as floor
roundTruncate :: Integral n => a -> n Source #
Truncate to the closest integral to the fractional number closer to 0.
This is equivalent to roundUp for negative Number and roundDown for positive Number
roundNearest :: Integral n => a -> n Source #
Round to the nearest integral
roundNearest 3.6
4 > roundNearest 3.4 3
class FloatingPoint a where Source #
IEEE754 Floating Point
floatRadix :: Proxy a -> Integer Source #
floatDigits :: Proxy a -> Int Source #
floatRange :: Proxy a -> (Int, Int) Source #
floatDecode :: a -> (Integer, Int) Source #
floatEncode :: Integer -> Int -> a Source #