foundation-0.0.13: Alternative prelude with batteries and no dependencies

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 Source #

Number literals, convertible through the generic Integer type.

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

Minimal complete definition

toInteger

Methods

toInteger :: a -> Integer Source #

Instances

 Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods IsIntegral (Offset ty) Source # Methods

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

Non Negative Number literals, convertible through the generic Natural type

Minimal complete definition

toNatural

Methods

toNatural :: a -> Natural Source #

Instances

 Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods IsNatural (CountOf ty) Source # Methods IsNatural (Offset ty) Source # Methods

class Signed a where Source #

types that have sign and can be made absolute

Minimal complete definition

Methods

abs :: a -> a Source #

signum :: a -> Sign Source #

Instances

 Source # Methods Source # Methods Source # Methodsabs :: Int -> Int Source # Source # Methods Source # Methods Source # Methods Source # Methods Source # Methods

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

Minimal complete definition

Methods

azero :: a Source #

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

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

Instances

 Source # Methodsscale :: IsNatural n => n -> Double -> Double Source # Source # Methodsscale :: IsNatural n => n -> Float -> Float Source # Source # Methods(+) :: Int -> Int -> Int Source #scale :: IsNatural n => n -> Int -> Int Source # Source # Methods(+) :: Int8 -> Int8 -> Int8 Source #scale :: IsNatural n => n -> Int8 -> Int8 Source # Source # Methodsscale :: IsNatural n => n -> Int16 -> Int16 Source # Source # Methodsscale :: IsNatural n => n -> Int32 -> Int32 Source # Source # Methodsscale :: IsNatural n => n -> Int64 -> Int64 Source # Source # Methodsscale :: IsNatural n => n -> Integer -> Integer Source # Source # Methods(+) :: Word -> Word -> Word Source #scale :: IsNatural n => n -> Word -> Word Source # Source # Methodsscale :: IsNatural n => n -> Word8 -> Word8 Source # Source # Methodsscale :: IsNatural n => n -> Word16 -> Word16 Source # Source # Methodsscale :: IsNatural n => n -> Word32 -> Word32 Source # Source # Methodsscale :: IsNatural n => n -> Word64 -> Word64 Source # Source # Methodsscale :: IsNatural n => n -> Natural -> Natural Source # Source # Methodsscale :: IsNatural n => n -> CSize -> CSize Source # Source # Methodsscale :: IsNatural n => n -> Seconds -> Seconds Source # Source # Methodsscale :: IsNatural n => n -> NanoSeconds -> NanoSeconds Source # Additive (CountOf ty) Source # Methods(+) :: CountOf ty -> CountOf ty -> CountOf ty Source #scale :: IsNatural n => n -> CountOf ty -> CountOf ty Source # Additive (Offset ty) Source # Methods(+) :: Offset ty -> Offset ty -> Offset ty Source #scale :: IsNatural n => n -> Offset ty -> Offset ty Source #

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

Minimal complete definition

(-)

Associated Types

type Difference a Source #

Methods

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

Instances

 Source # Associated Typestype Difference Char :: * Source # Methods Source # Associated Typestype Difference Double :: * Source # Methods Source # Associated Typestype Difference Float :: * Source # Methods Source # Associated Typestype Difference Int :: * Source # Methods Source # Associated Typestype Difference Int8 :: * Source # Methods Source # Associated Typestype Difference Int16 :: * Source # Methods Source # Associated Typestype Difference Int32 :: * Source # Methods Source # Associated Typestype Difference Int64 :: * Source # Methods Source # Associated Types Methods Source # Associated Typestype Difference Word :: * Source # Methods Source # Associated Typestype Difference Word8 :: * Source # Methods Source # Associated Typestype Difference Word16 :: * Source # Methods Source # Associated Typestype Difference Word32 :: * Source # Methods Source # Associated Typestype Difference Word64 :: * Source # Methods Source # Associated Types Methods Source # Associated Typestype Difference (CountOf ty) :: * Source # Methods(-) :: CountOf ty -> CountOf ty -> Difference (CountOf ty) Source # Source # Associated Typestype Difference (Offset ty) :: * Source # Methods(-) :: Offset ty -> Offset ty -> Difference (Offset ty) Source #

class Multiplicative a where Source #

Represent class of things that can be multiplied together

x * midentity = x
midentity * x = x

Minimal complete definition

Methods

midentity :: a Source #

Identity element over multiplication

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

Multiplication of 2 elements that result in another element

(^) :: (IsNatural 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

 Source # Methods(^) :: (IsNatural n, IDivisible n) => Double -> n -> Double Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Float -> n -> Float Source # Source # Methods(*) :: Int -> Int -> Int Source #(^) :: (IsNatural n, IDivisible n) => Int -> n -> Int Source # Source # Methods(*) :: Int8 -> Int8 -> Int8 Source #(^) :: (IsNatural n, IDivisible n) => Int8 -> n -> Int8 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Int16 -> n -> Int16 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Int32 -> n -> Int32 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Int64 -> n -> Int64 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Integer -> n -> Integer Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Rational -> n -> Rational Source # Source # Methods(*) :: Word -> Word -> Word Source #(^) :: (IsNatural n, IDivisible n) => Word -> n -> Word Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Word8 -> n -> Word8 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Word16 -> n -> Word16 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Word32 -> n -> Word32 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Word64 -> n -> Word64 Source # Source # Methods(^) :: (IsNatural n, IDivisible n) => Natural -> n -> Natural Source #

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

Represent types that supports an euclidian division

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

Minimal complete definition

Methods

div :: a -> a -> a Source #

mod :: a -> a -> a Source #

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

Instances

 Source # Methodsdiv :: Int -> Int -> Int Source #mod :: Int -> Int -> Int Source #divMod :: Int -> Int -> (Int, Int) Source # Source # Methodsdiv :: Int8 -> Int8 -> Int8 Source #mod :: Int8 -> Int8 -> Int8 Source #divMod :: Int8 -> Int8 -> (Int8, Int8) Source # Source # MethodsdivMod :: Int16 -> Int16 -> (Int16, Int16) Source # Source # MethodsdivMod :: Int32 -> Int32 -> (Int32, Int32) Source # Source # MethodsdivMod :: Int64 -> Int64 -> (Int64, Int64) Source # Source # Methods Source # Methodsdiv :: Word -> Word -> Word Source #mod :: Word -> Word -> Word Source #divMod :: Word -> Word -> (Word, Word) Source # Source # MethodsdivMod :: Word8 -> Word8 -> (Word8, Word8) Source # Source # MethodsdivMod :: Word16 -> Word16 -> (Word16, Word16) Source # Source # MethodsdivMod :: Word32 -> Word32 -> (Word32, Word32) Source # Source # MethodsdivMod :: Word64 -> Word64 -> (Word64, Word64) Source # Source # Methods

class Multiplicative a => Divisible a where Source #

Support for division between same types

This is likely to change to represent specific mathematic divisions

Minimal complete definition

(/)

Methods

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

Instances

 Source # Methods Source # Methods Source # Methods

data Sign Source #

Sign of a signed number

Constructors

 SignNegative SignZero SignPositive

Instances

 Source # Methods(==) :: Sign -> Sign -> Bool #(/=) :: Sign -> Sign -> Bool #

recip :: Divisible a => a -> a Source #

class IntegralRounding a where Source #

Minimal complete definition

Methods

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

Instances

 Source # MethodsroundUp :: Integral n => Double -> n Source #roundDown :: Integral n => Double -> n Source #roundTruncate :: Integral n => Double -> n Source #roundNearest :: Integral n => Double -> n Source # Source # MethodsroundUp :: Integral n => Float -> n Source #roundDown :: Integral n => Float -> n Source #roundTruncate :: Integral n => Float -> n Source #roundNearest :: Integral n => Float -> n Source # Source # MethodsroundUp :: Integral n => Rational -> n Source #roundDown :: Integral n => Rational -> n Source #roundTruncate :: Integral n => Rational -> n Source #roundNearest :: Integral n => Rational -> n Source #

class FloatingPoint a where Source #

IEEE754 Floating Point

Minimal complete definition

Instances

 Source # Methods Source # Methods