License | BSD-style |
---|---|
Maintainer | Vincent Hanquez <vincent@snarc.org> |
Stability | experimental |
Portability | portable |
Safe Haskell | None |
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.
- class (Eq a, Ord a, Num a, Enum a, Additive a, Subtractive a, Difference a ~ a, Multiplicative a, Divisible a) => Number a where
- fromInteger :: Number a => Integer -> a
- class Number a => Signed a where
- class Additive a where
- class Multiplicative a where
- class Subtractive a where
- type Difference a
- class Multiplicative a => Divisible a where
- data Sign
Documentation
class (Eq a, Ord a, Num a, Enum a, Additive a, Subtractive a, Difference a ~ a, Multiplicative a, Divisible a) => Number a where Source #
Number literals, convertible through the generic Integer type.
all number are Enum'erable, meaning that you can move to next element
fromInteger :: Number a => Integer -> a Source #
convert an Integer to a type having the Number constraint
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
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
(^) :: Number n => a -> n -> a infixr 8 Source #
Raise to power, repeated multiplication e.g. > a ^ 2 = a * a > a ^ 10 = (a ^ 5) * (a ^ 5) ..
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: e.g. (-) :: Int -> Int -> Int (-) :: DateTime -> DateTime -> Seconds (-) :: Ptr a -> Ptr a -> PtrDiff
type Difference a Source #
(-) :: a -> a -> Difference a infixl 6 Source #
class Multiplicative a => Divisible a where Source #
Represent class of things that can be divided
(x ‘div‘ y) * y + (x ‘mod‘ y) == x