HORIZON HASKELLDocslts/ghc-10.0.x77a86622026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 77a8662 · 2026-10-31

Modulefoundation-0.0.30Haskell2010

Foundation.Numerical

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
  • Packagefoundation-0.0.30
  • Exports12
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceNumerical.hs
classclass (Integral a, Eq a, Ord 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

Instances38IsIntegral, …
classclass IsIntegral a => IsNatural a where

Non Negative Number literals, convertible through the generic Natural type

Methods

Instances20IsNatural, …
classclass Signed a where

types that have sign and can be made absolute

Methods

Instances8Signed, …
  • Signed IntegerDefined in foundation-0.0.30 · Foundation.Numerical
  • Signed Int16Defined in foundation-0.0.30 · Foundation.Numerical
  • Signed Int32Defined in foundation-0.0.30 · Foundation.Numerical
  • Signed Int64Defined in foundation-0.0.30 · Foundation.Numerical
  • Signed Int8Defined in foundation-0.0.30 · Foundation.Numerical
  • Signed DoubleDefined in foundation-0.0.30 · Foundation.Numerical
  • Signed FloatDefined in foundation-0.0.30 · Foundation.Numerical
  • Signed IntDefined in foundation-0.0.30 · Foundation.Numerical
classclass 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

Methods

Instances50Additive, …
classclass 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

Methods

Instances49Subtractive, …
classclass Multiplicative a where

Represent class of things that can be multiplied together

x * midentity = x
midentity * x = x

Methods

  • midentity :: a

    Identity element over multiplication

  • (*) :: a -> a -> ainfixl 7

    Multiplication of 2 elements that result in another element

  • (^) :: (IsNatural n, Enum n, IDivisible n) => a -> n -> ainfixr 8

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

Instances44Multiplicative, …
classclass (Additive a, Multiplicative a) => IDivisible a where

Represent types that supports an euclidian division

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

Methods

  • div :: a -> a -> a
  • mod :: a -> a -> a
  • divMod :: a -> a -> (a, a)
Instances34IDivisible, …
  • IDivisible Word128Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Word256Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible IntegerDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible NaturalDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CCharDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CIntDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CIntMaxDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CIntPtrDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CLLongDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CLongDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CPtrdiffDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CSCharDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CShortDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CSigAtomicDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CSizeDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CUCharDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CUIntDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CUIntMaxDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CUIntPtrDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CULLongDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CULongDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CUShortDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible CWcharDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Int16Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Int32Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Int64Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Int8Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible IntDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible WordDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Word16Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Word32Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Word64Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • IDivisible Word8Defined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • SizeValid n => IDivisible (Bits n)Defined in basement-0.0.16 · Basement.Bits
classclass Multiplicative a => Divisible a where

Support for division between same types

This is likely to change to represent specific mathematic divisions

Methods

  • (/) :: a -> a -> ainfixl 7
Instances5Divisible
  • Divisible CDoubleDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • Divisible CFloatDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • Divisible RationalDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • Divisible DoubleDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
  • Divisible FloatDefined in basement-0.0.16 · Basement.Numerical.Multiplicative
classclass 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

Instances3IntegralRounding