ghc-internal-9.1400.0: Basic libraries
Copyright(c) The University of Glasgow 1994-2002
Licensesee libraries/base/LICENSE
Maintainerghc-devs@haskell.org
Stabilityinternal
Portabilitynon-portable (GHC Extensions)
Safe HaskellTrustworthy
LanguageHaskell2010

GHC.Internal.Num

Description

The Num class and the Integer type.

Synopsis

Documentation

class Num a where #

Basic numeric class.

The Haskell Report defines no laws for Num. However, (+) and (*) are customarily expected to define a ring and have the following properties:

Associativity of (+)
(x + y) + z = x + (y + z)
Commutativity of (+)
x + y = y + x
fromInteger 0 is the additive identity
x + fromInteger 0 = x
negate gives the additive inverse
x + negate x = fromInteger 0
Associativity of (*)
(x * y) * z = x * (y * z)
fromInteger 1 is the multiplicative identity
x * fromInteger 1 = x and fromInteger 1 * x = x
Distributivity of (*) with respect to (+)
a * (b + c) = (a * b) + (a * c) and (b + c) * a = (b * a) + (c * a)
Coherence with toInteger
if the type also implements Integral, then fromInteger is a left inverse for toInteger, i.e. fromInteger (toInteger i) == i

Note that it isn't customarily expected that a type instance of both Num and Ord implement an ordered ring. Indeed, in base only Integer and Rational do.

Minimal complete definition

(+), (*), abs, signum, fromInteger, (negate | (-))

Methods

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

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

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

negate :: a -> a #

Unary negation.

abs :: a -> a #

Absolute value.

signum :: a -> a #

Sign of a number. The functions abs and signum should satisfy the law:

abs x * signum x == x

For real numbers, the signum is either -1 (negative), 0 (zero) or 1 (positive).

fromInteger :: Integer -> a #

Conversion from an Integer. An integer literal represents the application of the function fromInteger to the appropriate value of type Integer, so such literals have type (Num a) => a.

Instances

Instances details
Num CBool # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CClock # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CDouble # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CFloat # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CInt # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

(+) :: CInt -> CInt -> CInt #

(-) :: CInt -> CInt -> CInt #

(*) :: CInt -> CInt -> CInt #

negate :: CInt -> CInt #

abs :: CInt -> CInt #

signum :: CInt -> CInt #

fromInteger :: Integer -> CInt #

Num CIntMax # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CIntPtr # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CLLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CPtrdiff # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CSChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CSUSeconds # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CShort # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CSigAtomic # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CSize # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CTime # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CUChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CUInt # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CUIntMax # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CUIntPtr # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CULLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CULong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CUSeconds # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CUShort # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num CWchar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Num IntPtr # 
Instance details

Defined in GHC.Internal.Foreign.Ptr

Num WordPtr # 
Instance details

Defined in GHC.Internal.Foreign.Ptr

Num HalfWord # 
Instance details

Defined in GHC.Internal.Heap.InfoTable.Types

Num Int16 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Num Int32 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Num Int64 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Num Int8 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Methods

(+) :: Int8 -> Int8 -> Int8 #

(-) :: Int8 -> Int8 -> Int8 #

(*) :: Int8 -> Int8 -> Int8 #

negate :: Int8 -> Int8 #

abs :: Int8 -> Int8 #

signum :: Int8 -> Int8 #

fromInteger :: Integer -> Int8 #

Num ByteOffset # 
Instance details

Defined in GHC.Internal.Stack.Constants

Num WordOffset # 
Instance details

Defined in GHC.Internal.Stack.Constants

Num ByteOffset # 
Instance details

Defined in GHC.Internal.Stack.ConstantsProf

Num WordOffset # 
Instance details

Defined in GHC.Internal.Stack.ConstantsProf

Num CBlkCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CBlkSize # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CCc # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CCc -> CCc -> CCc #

(-) :: CCc -> CCc -> CCc #

(*) :: CCc -> CCc -> CCc #

negate :: CCc -> CCc #

abs :: CCc -> CCc #

signum :: CCc -> CCc #

fromInteger :: Integer -> CCc #

Num CClockId # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CDev # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CDev -> CDev -> CDev #

(-) :: CDev -> CDev -> CDev #

(*) :: CDev -> CDev -> CDev #

negate :: CDev -> CDev #

abs :: CDev -> CDev #

signum :: CDev -> CDev #

fromInteger :: Integer -> CDev #

Num CFsBlkCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CFsFilCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CGid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CGid -> CGid -> CGid #

(-) :: CGid -> CGid -> CGid #

(*) :: CGid -> CGid -> CGid #

negate :: CGid -> CGid #

abs :: CGid -> CGid #

signum :: CGid -> CGid #

fromInteger :: Integer -> CGid #

Num CId # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CId -> CId -> CId #

(-) :: CId -> CId -> CId #

(*) :: CId -> CId -> CId #

negate :: CId -> CId #

abs :: CId -> CId #

signum :: CId -> CId #

fromInteger :: Integer -> CId #

Num CIno # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CIno -> CIno -> CIno #

(-) :: CIno -> CIno -> CIno #

(*) :: CIno -> CIno -> CIno #

negate :: CIno -> CIno #

abs :: CIno -> CIno #

signum :: CIno -> CIno #

fromInteger :: Integer -> CIno #

Num CKey # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CKey -> CKey -> CKey #

(-) :: CKey -> CKey -> CKey #

(*) :: CKey -> CKey -> CKey #

negate :: CKey -> CKey #

abs :: CKey -> CKey #

signum :: CKey -> CKey #

fromInteger :: Integer -> CKey #

Num CMode # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CNfds # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CNlink # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num COff # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: COff -> COff -> COff #

(-) :: COff -> COff -> COff #

(*) :: COff -> COff -> COff #

negate :: COff -> COff #

abs :: COff -> COff #

signum :: COff -> COff #

fromInteger :: Integer -> COff #

Num CPid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CPid -> CPid -> CPid #

(-) :: CPid -> CPid -> CPid #

(*) :: CPid -> CPid -> CPid #

negate :: CPid -> CPid #

abs :: CPid -> CPid #

signum :: CPid -> CPid #

fromInteger :: Integer -> CPid #

Num CRLim # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CSocklen # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CSpeed # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CSsize # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CTcflag # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Num CUid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: CUid -> CUid -> CUid #

(-) :: CUid -> CUid -> CUid #

(*) :: CUid -> CUid -> CUid #

negate :: CUid -> CUid #

abs :: CUid -> CUid #

signum :: CUid -> CUid #

fromInteger :: Integer -> CUid #

Num Fd # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

(+) :: Fd -> Fd -> Fd #

(-) :: Fd -> Fd -> Fd #

(*) :: Fd -> Fd -> Fd #

negate :: Fd -> Fd #

abs :: Fd -> Fd #

signum :: Fd -> Fd #

fromInteger :: Integer -> Fd #

Num Word16 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Num Word32 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Num Word64 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Num Word8 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Num Integer #

Since: base-2.1

Instance details

Defined in GHC.Internal.Num

Num Natural #

Note that Natural's Num instance isn't a ring: no element but 0 has an additive inverse. It is a semiring though.

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Num

Num Double #

This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:

>>> (0.1 + 0.1) + 0.4 == 0.1 + (0.1 + 0.4)
False
>>> (0.1 + 0.2) * 0.3 == 0.1 * 0.3 + 0.2 * 0.3
False
>>> (0.1 * 0.1) * 0.3 == 0.1 * (0.1 * 0.3)
False

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Num Float #

This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:

>>> (0.1 + 0.1 :: Float) + 0.5 == 0.1 + (0.1 + 0.5)
False
>>> (0.1 + 0.2 :: Float) * 0.9 == 0.1 * 0.9 + 0.2 * 0.9
False
>>> (0.1 * 0.1 :: Float) * 0.9 == 0.1 * (0.1 * 0.9)
False

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Num Int #

Since: base-2.1

Instance details

Defined in GHC.Internal.Num

Methods

(+) :: Int -> Int -> Int #

(-) :: Int -> Int -> Int #

(*) :: Int -> Int -> Int #

negate :: Int -> Int #

abs :: Int -> Int #

signum :: Int -> Int #

fromInteger :: Integer -> Int #

Num Word #

Since: base-2.1

Instance details

Defined in GHC.Internal.Num

Methods

(+) :: Word -> Word -> Word #

(-) :: Word -> Word -> Word #

(*) :: Word -> Word -> Word #

negate :: Word -> Word #

abs :: Word -> Word #

signum :: Word -> Word #

fromInteger :: Integer -> Word #

Num a => Num (Identity a) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Identity

Num a => Num (Down a) #

Since: base-4.11.0.0

Instance details

Defined in GHC.Internal.Data.Ord

Methods

(+) :: Down a -> Down a -> Down a #

(-) :: Down a -> Down a -> Down a #

(*) :: Down a -> Down a -> Down a #

negate :: Down a -> Down a #

abs :: Down a -> Down a #

signum :: Down a -> Down a #

fromInteger :: Integer -> Down a #

Num a => Num (Product a) #

Since: base-4.7.0.0

Instance details

Defined in GHC.Internal.Data.Semigroup.Internal

Methods

(+) :: Product a -> Product a -> Product a #

(-) :: Product a -> Product a -> Product a #

(*) :: Product a -> Product a -> Product a #

negate :: Product a -> Product a #

abs :: Product a -> Product a #

signum :: Product a -> Product a #

fromInteger :: Integer -> Product a #

Num a => Num (Sum a) #

Since: base-4.7.0.0

Instance details

Defined in GHC.Internal.Data.Semigroup.Internal

Methods

(+) :: Sum a -> Sum a -> Sum a #

(-) :: Sum a -> Sum a -> Sum a #

(*) :: Sum a -> Sum a -> Sum a #

negate :: Sum a -> Sum a #

abs :: Sum a -> Sum a #

signum :: Sum a -> Sum a #

fromInteger :: Integer -> Sum a #

Integral a => Num (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

(+) :: Ratio a -> Ratio a -> Ratio a #

(-) :: Ratio a -> Ratio a -> Ratio a #

(*) :: Ratio a -> Ratio a -> Ratio a #

negate :: Ratio a -> Ratio a #

abs :: Ratio a -> Ratio a #

signum :: Ratio a -> Ratio a #

fromInteger :: Integer -> Ratio a #

Num a => Num (Const a b) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Const

Methods

(+) :: Const a b -> Const a b -> Const a b #

(-) :: Const a b -> Const a b -> Const a b #

(*) :: Const a b -> Const a b -> Const a b #

negate :: Const a b -> Const a b #

abs :: Const a b -> Const a b #

signum :: Const a b -> Const a b #

fromInteger :: Integer -> Const a b #

(Applicative f, Num a) => Num (Ap f a) #

Note that even if the underlying Num and Applicative instances are lawful, for most Applicatives, this instance will not be lawful. If you use this instance with the list Applicative, the following customary laws will not hold:

Commutativity:

>>> Ap [10,20] + Ap [1,2]
Ap {getAp = [11,12,21,22]}
>>> Ap [1,2] + Ap [10,20]
Ap {getAp = [11,21,12,22]}

Additive inverse:

>>> Ap [] + negate (Ap [])
Ap {getAp = []}
>>> fromInteger 0 :: Ap [] Int
Ap {getAp = [0]}

Distributivity:

>>> Ap [1,2] * (3 + 4)
Ap {getAp = [7,14]}
>>> (Ap [1,2] * 3) + (Ap [1,2] * 4)
Ap {getAp = [7,11,10,14]}

Since: base-4.12.0.0

Instance details

Defined in GHC.Internal.Data.Monoid

Methods

(+) :: Ap f a -> Ap f a -> Ap f a #

(-) :: Ap f a -> Ap f a -> Ap f a #

(*) :: Ap f a -> Ap f a -> Ap f a #

negate :: Ap f a -> Ap f a #

abs :: Ap f a -> Ap f a #

signum :: Ap f a -> Ap f a #

fromInteger :: Integer -> Ap f a #

Num (f a) => Num (Alt f a) #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Data.Semigroup.Internal

Methods

(+) :: Alt f a -> Alt f a -> Alt f a #

(-) :: Alt f a -> Alt f a -> Alt f a #

(*) :: Alt f a -> Alt f a -> Alt f a #

negate :: Alt f a -> Alt f a #

abs :: Alt f a -> Alt f a #

signum :: Alt f a -> Alt f a #

fromInteger :: Integer -> Alt f a #

subtract :: Num a => a -> a -> a #

the same as flip (-).

Because - is treated specially in the Haskell grammar, (- e) is not a section, but an application of prefix negation. However, (subtract exp) is equivalent to the disallowed section.

quotRemInteger :: Integer -> Integer -> (# Integer, Integer #) #

Deprecated: Use integerQuotRem# instead

data Natural #

Natural number

Invariant: numbers <= 0xffffffffffffffff use the NS constructor

Instances

Instances details
Bits Natural #

Since: base-4.8.0

Instance details

Defined in GHC.Internal.Bits

Eq Natural # 
Instance details

Defined in GHC.Internal.Bignum.Natural

Methods

(==) :: Natural -> Natural -> Bool #

(/=) :: Natural -> Natural -> Bool #

Ord Natural # 
Instance details

Defined in GHC.Internal.Bignum.Natural

Data Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Data.Data

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Natural -> c Natural #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Natural #

toConstr :: Natural -> Constr #

dataTypeOf :: Natural -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Natural) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Natural) #

gmapT :: (forall b. Data b => b -> b) -> Natural -> Natural #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r #

gmapQ :: (forall d. Data d => d -> u) -> Natural -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Natural -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Natural -> m Natural #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural #

Enum Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Enum

Ix Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Ix

Num Natural #

Note that Natural's Num instance isn't a ring: no element but 0 has an additive inverse. It is a semiring though.

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Num

Read Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Read

Integral Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Real

Real Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Real

Show Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Show

TestCoercion SNat #

Since: base-4.18.0.0

Instance details

Defined in GHC.Internal.TypeNats

Methods

testCoercion :: forall (a :: Nat) (b :: Nat). SNat a -> SNat b -> Maybe (Coercion a b) #

TestEquality SNat #

Since: base-4.18.0.0

Instance details

Defined in GHC.Internal.TypeNats

Methods

testEquality :: forall (a :: Nat) (b :: Nat). SNat a -> SNat b -> Maybe (a :~: b) #

Lift Natural # 
Instance details

Defined in GHC.Internal.TH.Lift

Methods

lift :: Quote m => Natural -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Natural -> Code m Natural #

type Compare (a :: Natural) (b :: Natural) # 
Instance details

Defined in GHC.Internal.Data.Type.Ord

type Compare (a :: Natural) (b :: Natural) = CmpNat a b

data Integer #

Arbitrary precision integers. In contrast with fixed-size integral types such as Int, the Integer type represents the entire infinite range of integers.

Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.

If the value is small (i.e., fits into an Int), the IS constructor is used. Otherwise IP and IN constructors are used to store a BigNat representing the positive or the negative value magnitude, respectively.

Invariant: IP and IN are used iff the value does not fit in IS.

Instances

Instances details
Bits Integer #

Since: base-2.1

Instance details

Defined in GHC.Internal.Bits

Eq Integer # 
Instance details

Defined in GHC.Internal.Bignum.Integer

Methods

(==) :: Integer -> Integer -> Bool #

(/=) :: Integer -> Integer -> Bool #

Ord Integer # 
Instance details

Defined in GHC.Internal.Bignum.Integer

Data Integer #

Since: base-4.0.0.0

Instance details

Defined in GHC.Internal.Data.Data

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Integer -> c Integer #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Integer #

toConstr :: Integer -> Constr #

dataTypeOf :: Integer -> DataType #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Integer) #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Integer) #

gmapT :: (forall b. Data b => b -> b) -> Integer -> Integer #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Integer -> r #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Integer -> r #

gmapQ :: (forall d. Data d => d -> u) -> Integer -> [u] #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Integer -> u #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Integer -> m Integer #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Integer -> m Integer #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Integer -> m Integer #

Enum Integer #

Since: base-2.1

Instance details

Defined in GHC.Internal.Enum

Ix Integer #

Since: base-2.1

Instance details

Defined in GHC.Internal.Ix

Num Integer #

Since: base-2.1

Instance details

Defined in GHC.Internal.Num

Read Integer #

Since: base-2.1

Instance details

Defined in GHC.Internal.Read

Integral Integer #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Real Integer #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Show Integer #

Since: base-2.1

Instance details

Defined in GHC.Internal.Show

Lift Integer # 
Instance details

Defined in GHC.Internal.TH.Lift

Methods

lift :: Quote m => Integer -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Integer -> Code m Integer #