foundation-0.0.29: Alternative prelude with batteries and no dependencies
License BSD-style
Maintainer Vincent Hanquez <vincent@snarc.org>
Stability experimental
Portability portable
Safe Haskell None
Language Haskell2010

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 ( 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

Instances details
IsIntegral Int
Instance details

Defined in Basement.Numerical.Number

IsIntegral Int8
Instance details

Defined in Basement.Numerical.Number

IsIntegral Int16
Instance details

Defined in Basement.Numerical.Number

IsIntegral Int32
Instance details

Defined in Basement.Numerical.Number

IsIntegral Int64
Instance details

Defined in Basement.Numerical.Number

IsIntegral Integer
Instance details

Defined in Basement.Numerical.Number

IsIntegral Natural
Instance details

Defined in Basement.Numerical.Number

IsIntegral Word
Instance details

Defined in Basement.Numerical.Number

IsIntegral Word8
Instance details

Defined in Basement.Numerical.Number

IsIntegral Word16
Instance details

Defined in Basement.Numerical.Number

IsIntegral Word32
Instance details

Defined in Basement.Numerical.Number

IsIntegral Word64
Instance details

Defined in Basement.Numerical.Number

IsIntegral CChar
Instance details

Defined in Basement.Numerical.Number

IsIntegral CSChar
Instance details

Defined in Basement.Numerical.Number

IsIntegral CUChar
Instance details

Defined in Basement.Numerical.Number

IsIntegral CShort
Instance details

Defined in Basement.Numerical.Number

IsIntegral CUShort
Instance details

Defined in Basement.Numerical.Number

IsIntegral CInt
Instance details

Defined in Basement.Numerical.Number

IsIntegral CUInt
Instance details

Defined in Basement.Numerical.Number

IsIntegral CLong
Instance details

Defined in Basement.Numerical.Number

IsIntegral CULong
Instance details

Defined in Basement.Numerical.Number

IsIntegral CLLong
Instance details

Defined in Basement.Numerical.Number

IsIntegral CULLong
Instance details

Defined in Basement.Numerical.Number

IsIntegral CBool
Instance details

Defined in Basement.Numerical.Number

IsIntegral CPtrdiff
Instance details

Defined in Basement.Numerical.Number

IsIntegral CSize
Instance details

Defined in Basement.Numerical.Number

IsIntegral CWchar
Instance details

Defined in Basement.Numerical.Number

IsIntegral CSigAtomic
Instance details

Defined in Basement.Numerical.Number

IsIntegral CIntPtr
Instance details

Defined in Basement.Numerical.Number

IsIntegral CUIntPtr
Instance details

Defined in Basement.Numerical.Number

IsIntegral CIntMax
Instance details

Defined in Basement.Numerical.Number

IsIntegral CUIntMax
Instance details

Defined in Basement.Numerical.Number

IsIntegral Word256
Instance details

Defined in Basement.Types.Word256

IsIntegral Word128
Instance details

Defined in Basement.Types.Word128

IsIntegral ( Offset ty)
Instance details

Defined in Basement.Types.OffsetSize

IsIntegral ( CountOf ty)
Instance details

Defined in Basement.Types.OffsetSize

( KnownNat n, NatWithinBound Word64 n) => IsIntegral ( Zn64 n)
Instance details

Defined in Basement.Bounded

KnownNat n => IsIntegral ( Zn n)
Instance details

Defined in Basement.Bounded

class IsIntegral a => IsNatural a where Source #

Non Negative Number literals, convertible through the generic Natural type

Instances

Instances details
IsNatural Natural
Instance details

Defined in Basement.Numerical.Number

IsNatural Word
Instance details

Defined in Basement.Numerical.Number

IsNatural Word8
Instance details

Defined in Basement.Numerical.Number

IsNatural Word16
Instance details

Defined in Basement.Numerical.Number

IsNatural Word32
Instance details

Defined in Basement.Numerical.Number

IsNatural Word64
Instance details

Defined in Basement.Numerical.Number

IsNatural CUChar
Instance details

Defined in Basement.Numerical.Number

IsNatural CUShort
Instance details

Defined in Basement.Numerical.Number

IsNatural CUInt
Instance details

Defined in Basement.Numerical.Number

IsNatural CULong
Instance details

Defined in Basement.Numerical.Number

IsNatural CULLong
Instance details

Defined in Basement.Numerical.Number

IsNatural CSize
Instance details

Defined in Basement.Numerical.Number

IsNatural CUIntPtr
Instance details

Defined in Basement.Numerical.Number

IsNatural CUIntMax
Instance details

Defined in Basement.Numerical.Number

IsNatural Word256
Instance details

Defined in Basement.Types.Word256

IsNatural Word128
Instance details

Defined in Basement.Types.Word128

IsNatural ( Offset ty)
Instance details

Defined in Basement.Types.OffsetSize

IsNatural ( CountOf ty)
Instance details

Defined in Basement.Types.OffsetSize

( KnownNat n, NatWithinBound Word64 n) => IsNatural ( Zn64 n)
Instance details

Defined in Basement.Bounded

KnownNat n => IsNatural ( Zn n)
Instance details

Defined in Basement.Bounded

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

azero , (+)

Methods

azero :: a Source #

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

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

Instances

Instances details
Additive Double
Instance details

Defined in Basement.Numerical.Additive

Additive Float
Instance details

Defined in Basement.Numerical.Additive

Additive Int
Instance details

Defined in Basement.Numerical.Additive

Additive Int8
Instance details

Defined in Basement.Numerical.Additive

Additive Int16
Instance details

Defined in Basement.Numerical.Additive

Additive Int32
Instance details

Defined in Basement.Numerical.Additive

Additive Int64
Instance details

Defined in Basement.Numerical.Additive

Additive Integer
Instance details

Defined in Basement.Numerical.Additive

Additive Natural
Instance details

Defined in Basement.Numerical.Additive

Additive Rational
Instance details

Defined in Basement.Numerical.Additive

Additive Word
Instance details

Defined in Basement.Numerical.Additive

Additive Word8
Instance details

Defined in Basement.Numerical.Additive

Additive Word16
Instance details

Defined in Basement.Numerical.Additive

Additive Word32
Instance details

Defined in Basement.Numerical.Additive

Additive Word64
Instance details

Defined in Basement.Numerical.Additive

Additive COff
Instance details

Defined in Basement.Numerical.Additive

Additive CChar
Instance details

Defined in Basement.Numerical.Additive

Additive CSChar
Instance details

Defined in Basement.Numerical.Additive

Additive CUChar
Instance details

Defined in Basement.Numerical.Additive

Additive CShort
Instance details

Defined in Basement.Numerical.Additive

Additive CUShort
Instance details

Defined in Basement.Numerical.Additive

Additive CInt
Instance details

Defined in Basement.Numerical.Additive

Additive CUInt
Instance details

Defined in Basement.Numerical.Additive

Additive CLong
Instance details

Defined in Basement.Numerical.Additive

Additive CULong
Instance details

Defined in Basement.Numerical.Additive

Additive CLLong
Instance details

Defined in Basement.Numerical.Additive

Additive CULLong
Instance details

Defined in Basement.Numerical.Additive

Additive CFloat
Instance details

Defined in Basement.Numerical.Additive

Additive CDouble
Instance details

Defined in Basement.Numerical.Additive

Additive CPtrdiff
Instance details

Defined in Basement.Numerical.Additive

Additive CSize
Instance details

Defined in Basement.Numerical.Additive

Additive CWchar
Instance details

Defined in Basement.Numerical.Additive

Additive CSigAtomic
Instance details

Defined in Basement.Numerical.Additive

Additive CClock
Instance details

Defined in Basement.Numerical.Additive

Additive CTime
Instance details

Defined in Basement.Numerical.Additive

Additive CUSeconds
Instance details

Defined in Basement.Numerical.Additive

Additive CSUSeconds
Instance details

Defined in Basement.Numerical.Additive

Additive CIntPtr
Instance details

Defined in Basement.Numerical.Additive

Additive CUIntPtr
Instance details

Defined in Basement.Numerical.Additive

Additive CIntMax
Instance details

Defined in Basement.Numerical.Additive

Additive CUIntMax
Instance details

Defined in Basement.Numerical.Additive

Additive Word256
Instance details

Defined in Basement.Numerical.Additive

Additive Word128
Instance details

Defined in Basement.Numerical.Additive

Additive Seconds Source #
Instance details

Defined in Foundation.Time.Types

Additive NanoSeconds Source #
Instance details

Defined in Foundation.Time.Types

SizeValid n => Additive ( Bits n)
Instance details

Defined in Basement.Bits

Additive ( Offset ty)
Instance details

Defined in Basement.Types.OffsetSize

Additive ( CountOf ty)
Instance details

Defined in Basement.Types.OffsetSize

( KnownNat n, NatWithinBound Word64 n) => Additive ( Zn64 n)
Instance details

Defined in Basement.Numerical.Additive

KnownNat n => Additive ( Zn n)
Instance details

Defined in Basement.Numerical.Additive

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

Associated Types

type Difference a Source #

Methods

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

Instances

Instances details
Subtractive Char
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Double
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Float
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Int
Instance details

Defined in Basement.Numerical.Subtractive

Associated Types

type Difference Int Source #

Subtractive Int8
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Int16
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Int32
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Int64
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Integer
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Natural
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Word
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Word8
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Word16
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Word32
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Word64
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive COff
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CChar
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CSChar
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CUChar
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CShort
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CUShort
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CInt
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CUInt
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CLong
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CULong
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CLLong
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CULLong
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CBool
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CFloat
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CDouble
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CPtrdiff
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CSize
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CWchar
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CSigAtomic
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CClock
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CTime
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CUSeconds
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CSUSeconds
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CIntPtr
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CUIntPtr
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CIntMax
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive CUIntMax
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Word256
Instance details

Defined in Basement.Numerical.Subtractive

Subtractive Word128
Instance details

Defined in Basement.Numerical.Subtractive

SizeValid n => Subtractive ( Bits n)
Instance details

Defined in Basement.Bits

Associated Types

type Difference ( Bits n) Source #

Subtractive ( Offset ty)
Instance details

Defined in Basement.Types.OffsetSize

Associated Types

type Difference ( Offset ty) Source #

Subtractive ( CountOf ty)
Instance details

Defined in Basement.Types.OffsetSize

Associated Types

type Difference ( CountOf ty) Source #

( KnownNat n, NatWithinBound Word64 n) => Subtractive ( Zn64 n)
Instance details

Defined in Basement.Numerical.Subtractive

Associated Types

type Difference ( Zn64 n) Source #

KnownNat n => Subtractive ( Zn n)
Instance details

Defined in Basement.Numerical.Subtractive

Associated Types

type Difference ( Zn n) Source #

class Multiplicative a where Source #

Represent class of things that can be multiplied together

x * midentity = x
midentity * x = x

Minimal complete definition

midentity , (*)

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, 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

Instances details
Multiplicative Double
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Float
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Int
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Int8
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Int16
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Int32
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Int64
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Integer
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Natural
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Rational
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Word
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Word8
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Word16
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Word32
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Word64
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative COff
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CChar
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CSChar
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CUChar
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CShort
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CUShort
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CInt
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CUInt
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CLong
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CULong
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CLLong
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CULLong
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CFloat
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CDouble
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CPtrdiff
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CSize
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CWchar
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CSigAtomic
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CClock
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CTime
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CUSeconds
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CSUSeconds
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CIntPtr
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CUIntPtr
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CIntMax
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative CUIntMax
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Word256
Instance details

Defined in Basement.Numerical.Multiplicative

Multiplicative Word128
Instance details

Defined in Basement.Numerical.Multiplicative

SizeValid n => Multiplicative ( Bits n)
Instance details

Defined in Basement.Bits

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

div , mod | divMod

Methods

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

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

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

Instances

Instances details
IDivisible Int
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Int8
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Int16
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Int32
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Int64
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Integer
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Natural
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Word
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Word8
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Word16
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Word32
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Word64
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CChar
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CSChar
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CUChar
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CShort
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CUShort
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CInt
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CUInt
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CLong
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CULong
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CLLong
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CULLong
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CPtrdiff
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CSize
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CWchar
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CSigAtomic
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CIntPtr
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CUIntPtr
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CIntMax
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible CUIntMax
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Word256
Instance details

Defined in Basement.Numerical.Multiplicative

IDivisible Word128
Instance details

Defined in Basement.Numerical.Multiplicative

SizeValid n => IDivisible ( Bits n)
Instance details

Defined in Basement.Bits

class Multiplicative a => Divisible a where Source #

Support for division between same types

This is likely to change to represent specific mathematic divisions

Methods

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

class IntegralRounding a where Source #

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