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

GHC.Num

Description

The Num class and the Integer type.

Synopsis

Documentation

class Num a where Source #

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)

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

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

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

negate :: a -> a Source #

Unary negation.

abs :: a -> a Source #

Absolute value.

signum :: a -> a Source #

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

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

Defined in Foreign.C.Types

Num CChar Source # 
Instance details

Defined in Foreign.C.Types

Num CClock Source # 
Instance details

Defined in Foreign.C.Types

Num CDouble Source # 
Instance details

Defined in Foreign.C.Types

Num CFloat Source # 
Instance details

Defined in Foreign.C.Types

Num CInt Source # 
Instance details

Defined in Foreign.C.Types

Num CIntMax Source # 
Instance details

Defined in Foreign.C.Types

Num CIntPtr Source # 
Instance details

Defined in Foreign.C.Types

Num CLLong Source # 
Instance details

Defined in Foreign.C.Types

Num CLong Source # 
Instance details

Defined in Foreign.C.Types

Num CPtrdiff Source # 
Instance details

Defined in Foreign.C.Types

Num CSChar Source # 
Instance details

Defined in Foreign.C.Types

Num CSUSeconds Source # 
Instance details

Defined in Foreign.C.Types

Num CShort Source # 
Instance details

Defined in Foreign.C.Types

Num CSigAtomic Source # 
Instance details

Defined in Foreign.C.Types

Num CSize Source # 
Instance details

Defined in Foreign.C.Types

Num CTime Source # 
Instance details

Defined in Foreign.C.Types

Num CUChar Source # 
Instance details

Defined in Foreign.C.Types

Num CUInt Source # 
Instance details

Defined in Foreign.C.Types

Num CUIntMax Source # 
Instance details

Defined in Foreign.C.Types

Num CUIntPtr Source # 
Instance details

Defined in Foreign.C.Types

Num CULLong Source # 
Instance details

Defined in Foreign.C.Types

Num CULong Source # 
Instance details

Defined in Foreign.C.Types

Num CUSeconds Source # 
Instance details

Defined in Foreign.C.Types

Num CUShort Source # 
Instance details

Defined in Foreign.C.Types

Num CWchar Source # 
Instance details

Defined in Foreign.C.Types

Num IntPtr Source # 
Instance details

Defined in Foreign.Ptr

Num WordPtr Source # 
Instance details

Defined in Foreign.Ptr

Num Int16 Source #

Since: base-2.1

Instance details

Defined in GHC.Int

Num Int32 Source #

Since: base-2.1

Instance details

Defined in GHC.Int

Num Int64 Source #

Since: base-2.1

Instance details

Defined in GHC.Int

Num Int8 Source #

Since: base-2.1

Instance details

Defined in GHC.Int

Num Word16 Source #

Since: base-2.1

Instance details

Defined in GHC.Word

Num Word32 Source #

Since: base-2.1

Instance details

Defined in GHC.Word

Num Word64 Source #

Since: base-2.1

Instance details

Defined in GHC.Word

Num Word8 Source #

Since: base-2.1

Instance details

Defined in GHC.Word

Num CBlkCnt Source # 
Instance details

Defined in System.Posix.Types

Num CBlkSize Source # 
Instance details

Defined in System.Posix.Types

Num CCc Source # 
Instance details

Defined in System.Posix.Types

Num CClockId Source # 
Instance details

Defined in System.Posix.Types

Num CDev Source # 
Instance details

Defined in System.Posix.Types

Num CFsBlkCnt Source # 
Instance details

Defined in System.Posix.Types

Num CFsFilCnt Source # 
Instance details

Defined in System.Posix.Types