foundation-0.0.13: Alternative prelude with batteries and no dependencies

LicenseBSD-style
MaintainerVincent Hanquez <vincent@snarc.org>
Stabilityexperimental
Portabilityportable
Safe HaskellNone
LanguageHaskell2010

Foundation.Numerical

Description

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

Documentation

class (Enum a, Eq a, Ord a, Integral a) => IsIntegral a where

Number literals, convertible through the generic Integer type.

all number are Enum'erable, meaning that you can move to next element

Methods

toInteger :: a -> Integer

class (Enum a, Eq a, Ord a, Integral a, IsIntegral a) => IsNatural a where

Non Negative Number literals, convertible through the generic Natural type

Methods

toNatural :: a -> Natural

class Signed a where

types that have sign and can be made absolute

Methods

abs :: a -> a

signum :: a -> Sign

class Additive a where

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

Minimal complete definition

azero, (+)

Methods

azero :: a

(+) :: a -> a -> a infixl 6

scale :: IsNatural n => n -> a -> a

class Subtractive a where

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

Associated Types

type Difference a

Methods

(-) :: a -> a -> Difference a infixl 6

class Multiplicative a where

Represent class of things that can be multiplied together

x * midentity = x
midentity * x = x

Minimal complete definition

midentity, (*)

Methods

midentity :: a

Identity element over multiplication

(*) :: a -> a -> a infixl 7

Multiplication of 2 elements that result in another element

(^) :: (IsNatural n, IDivisible n) => a -> n -> a infixr 8

Raise to power, repeated multiplication e.g. > a ^ 2 = a * a > a ^ 10 = (a ^ 5) * (a ^ 5) .. (^) :: (IsNatural n) => a -> n -> a

class (Additive a, Multiplicative a) => IDivisible a where

Represent types that supports an euclidian division

(x ‘div‘ y) * y + (x ‘mod‘ y) == x

Minimal complete definition

div, mod | divMod

Methods

div :: a -> a -> a

mod :: a -> a -> a

divMod :: a -> a -> (a, a)

class Multiplicative a => Divisible a where

Support for division between same types

This is likely to change to represent specific mathematic divisions

Methods

(/) :: a -> a -> a infixl 7

data Sign

Sign of a signed number

Instances

recip :: Divisible a => a -> a

class IntegralRounding a where

Methods

roundUp :: Integral n => a -> n

Round up, to the next integral.

Also known as ceiling

roundDown :: Integral n => a -> n

Round down, to the previous integral

Also known as floor

roundTruncate :: Integral n => a -> n

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

Round to the nearest integral

roundNearest 3.6

4 > roundNearest 3.4 3

class FloatingPoint a where

IEEE754 Floating Point