| Copyright | (c) The University of Glasgow 1994-2002 |
|---|---|
| License | see libraries/base/LICENSE |
| Maintainer | ghc-devs@haskell.org |
| Stability | internal |
| Portability | non-portable (GHC Extensions) |
| Safe Haskell | None |
| Language | Haskell2010 |
GHC.Num
Synopsis
- class Num a where
- subtract :: Num a => a -> a -> a
- quotRemInteger :: Integer -> Integer -> (# Integer, Integer #)
- module GHC.Num.Integer
- module GHC.Num.Natural
Documentation
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 + xis the additive identityfromInteger0x + fromInteger 0=xnegategives the additive inversex + negate x=fromInteger 0- Associativity of
(*) (x * y) * z=x * (y * z)is the multiplicative identityfromInteger1x * fromInteger 1=xandfromInteger 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, thenfromIntegeris a left inverse fortoInteger, 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.
Methods
(+) :: a -> a -> a infixl 6 Source #
(-) :: a -> a -> a infixl 6 Source #
(*) :: a -> a -> a infixl 7 Source #
Unary negation.
Absolute value.
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
| Num Unique Source # | Since: base-4.4.0.0 |
Defined in GHC.Internal.Event.Unique | |
| Num CBool Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CChar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CClock Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CDouble Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CFloat Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CInt Source # | |
| Num CIntMax Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CIntPtr Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CLLong Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CLong Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CPtrdiff Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CPtrdiff -> CPtrdiff -> CPtrdiff Source # (-) :: CPtrdiff -> CPtrdiff -> CPtrdiff Source # (*) :: CPtrdiff -> CPtrdiff -> CPtrdiff Source # negate :: CPtrdiff -> CPtrdiff Source # abs :: CPtrdiff -> CPtrdiff Source # signum :: CPtrdiff -> CPtrdiff Source # fromInteger :: Integer -> CPtrdiff Source # | |
| Num CSChar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CSUSeconds Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CSUSeconds -> CSUSeconds -> CSUSeconds Source # (-) :: CSUSeconds -> CSUSeconds -> CSUSeconds Source # (*) :: CSUSeconds -> CSUSeconds -> CSUSeconds Source # negate :: CSUSeconds -> CSUSeconds Source # abs :: CSUSeconds -> CSUSeconds Source # signum :: CSUSeconds -> CSUSeconds Source # fromInteger :: Integer -> CSUSeconds Source # | |
| Num CShort Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CSigAtomic Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # (-) :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # (*) :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # negate :: CSigAtomic -> CSigAtomic Source # abs :: CSigAtomic -> CSigAtomic Source # signum :: CSigAtomic -> CSigAtomic Source # fromInteger :: Integer -> CSigAtomic Source # | |
| Num CSize Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CTime Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CUChar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CUInt Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CUIntMax Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CUIntMax -> CUIntMax -> CUIntMax Source # (-) :: CUIntMax -> CUIntMax -> CUIntMax Source # (*) :: CUIntMax -> CUIntMax -> CUIntMax Source # negate :: CUIntMax -> CUIntMax Source # abs :: CUIntMax -> CUIntMax Source # signum :: CUIntMax -> CUIntMax Source # fromInteger :: Integer -> CUIntMax Source # | |
| Num CUIntPtr Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CUIntPtr -> CUIntPtr -> CUIntPtr Source # (-) :: CUIntPtr -> CUIntPtr -> CUIntPtr Source # (*) :: CUIntPtr -> CUIntPtr -> CUIntPtr Source # negate :: CUIntPtr -> CUIntPtr Source # abs :: CUIntPtr -> CUIntPtr Source # signum :: CUIntPtr -> CUIntPtr Source # fromInteger :: Integer -> CUIntPtr Source # | |
| Num CULLong Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CULong Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CUSeconds Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CUSeconds -> CUSeconds -> CUSeconds Source # (-) :: CUSeconds -> CUSeconds -> CUSeconds Source # (*) :: CUSeconds -> CUSeconds -> CUSeconds Source # negate :: CUSeconds -> CUSeconds Source # abs :: CUSeconds -> CUSeconds Source # signum :: CUSeconds -> CUSeconds Source # fromInteger :: Integer -> CUSeconds Source # | |
| Num CUShort Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CWchar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num IntPtr Source # | |
Defined in GHC.Internal.Foreign.Ptr | |
| Num WordPtr Source # | |
Defined in GHC.Internal.Foreign.Ptr | |
| Num HalfWord Source # | |
Defined in GHC.Internal.Heap.InfoTable.Types Methods (+) :: HalfWord -> HalfWord -> HalfWord Source # (-) :: HalfWord -> HalfWord -> HalfWord Source # (*) :: HalfWord -> HalfWord -> HalfWord Source # negate :: HalfWord -> HalfWord Source # abs :: HalfWord -> HalfWord Source # signum :: HalfWord -> HalfWord Source # fromInteger :: Integer -> HalfWord Source # | |
| Num Int16 Source # | Since: base-2.1 |
| Num Int32 Source # | Since: base-2.1 |
| Num Int64 Source # | Since: base-2.1 |
| Num Int8 Source # | Since: base-2.1 |
| Num ByteOffset Source # | |
Defined in GHC.Internal.Stack.Constants Methods (+) :: ByteOffset -> ByteOffset -> ByteOffset Source # (-) :: ByteOffset -> ByteOffset -> ByteOffset Source # (*) :: ByteOffset -> ByteOffset -> ByteOffset Source # negate :: ByteOffset -> ByteOffset Source # abs :: ByteOffset -> ByteOffset Source # signum :: ByteOffset -> ByteOffset Source # fromInteger :: Integer -> ByteOffset Source # | |
| Num WordOffset Source # | |
Defined in GHC.Internal.Stack.Constants Methods (+) :: WordOffset -> WordOffset -> WordOffset Source # (-) :: WordOffset -> WordOffset -> WordOffset Source # (*) :: WordOffset -> WordOffset -> WordOffset Source # negate :: WordOffset -> WordOffset Source # abs :: WordOffset -> WordOffset Source # signum :: WordOffset -> WordOffset Source # fromInteger :: Integer -> WordOffset Source # | |
| Num ByteOffset Source # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods (+) :: ByteOffset -> ByteOffset -> ByteOffset Source # (-) :: ByteOffset -> ByteOffset -> ByteOffset Source # (*) :: ByteOffset -> ByteOffset -> ByteOffset Source # negate :: ByteOffset -> ByteOffset Source # abs :: ByteOffset -> ByteOffset Source # signum :: ByteOffset -> ByteOffset Source # fromInteger :: Integer -> ByteOffset Source # | |
| Num WordOffset Source # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods (+) :: WordOffset -> WordOffset -> WordOffset Source # (-) :: WordOffset -> WordOffset -> WordOffset Source # (*) :: WordOffset -> WordOffset -> WordOffset Source # negate :: WordOffset -> WordOffset Source # abs :: WordOffset -> WordOffset Source # signum :: WordOffset -> WordOffset Source # fromInteger :: Integer -> WordOffset Source # | |
| Num CBlkCnt Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CBlkSize Source # | |
Defined in GHC.Internal.System.Posix.Types Methods (+) :: CBlkSize -> CBlkSize -> CBlkSize Source # (-) :: CBlkSize -> CBlkSize -> CBlkSize Source # (*) :: CBlkSize -> CBlkSize -> CBlkSize Source # negate :: CBlkSize -> CBlkSize Source # abs :: CBlkSize -> CBlkSize Source # signum :: CBlkSize -> CBlkSize Source # fromInteger :: Integer -> CBlkSize Source # | |
| Num CCc Source # | |
| Num CClockId Source # | |
Defined in GHC.Internal.System.Posix.Types Methods (+) :: CClockId -> CClockId -> CClockId Source # (-) :: CClockId -> CClockId -> CClockId Source # (*) :: CClockId -> CClockId -> CClockId Source # negate :: CClockId -> CClockId Source # abs :: CClockId -> CClockId Source # signum :: CClockId -> CClockId Source # fromInteger :: Integer -> CClockId Source # | |
| Num CDev Source # | |
| Num CFsBlkCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods (+) :: CFsBlkCnt -> CFsBlkCnt -> CFsBlkCnt Source # (-) :: CFsBlkCnt -> CFsBlkCnt -> CFsBlkCnt Source # (*) :: CFsBlkCnt -> CFsBlkCnt -> CFsBlkCnt Source # negate :: CFsBlkCnt -> CFsBlkCnt Source # abs :: CFsBlkCnt -> CFsBlkCnt Source # signum :: CFsBlkCnt -> CFsBlkCnt Source # fromInteger :: Integer -> CFsBlkCnt Source # | |
| Num CFsFilCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods (+) :: CFsFilCnt -> CFsFilCnt -> CFsFilCnt Source # (-) :: CFsFilCnt -> CFsFilCnt -> CFsFilCnt Source # (*) :: CFsFilCnt -> CFsFilCnt -> CFsFilCnt Source # negate :: CFsFilCnt -> CFsFilCnt Source # abs :: CFsFilCnt -> CFsFilCnt Source # signum :: CFsFilCnt -> CFsFilCnt Source # fromInteger :: Integer -> CFsFilCnt Source # | |
| Num CGid Source # | |
| Num CId Source # | |
| Num CIno Source # | |
| Num CKey Source # | |
| Num CMode Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CNfds Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CNlink Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num COff Source # | |
| Num CPid Source # | |
| Num CRLim Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CSocklen Source # | |
Defined in GHC.Internal.System.Posix.Types Methods (+) :: CSocklen -> CSocklen -> CSocklen Source # (-) :: CSocklen -> CSocklen -> CSocklen Source # (*) :: CSocklen -> CSocklen -> CSocklen Source # negate :: CSocklen -> CSocklen Source # abs :: CSocklen -> CSocklen Source # signum :: CSocklen -> CSocklen Source # fromInteger :: Integer -> CSocklen Source # | |
| Num CSpeed Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CSsize Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CTcflag Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CUid Source # | |
| Num Fd Source # | |
| Num Word16 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Num Word32 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Num Word64 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Num Word8 Source # | Since: base-2.1 |
| Num Integer Source # | Since: base-2.1 |
Defined in GHC.Internal.Num | |
| Num Natural Source # | Note that Since: base-4.8.0.0 |
Defined in GHC.Internal.Num | |
| Num Double Source # | 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:
Since: base-2.1 |
Defined in GHC.Internal.Float | |
| Num Float Source # | 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:
Since: base-2.1 |
| Num Int Source # | Since: base-2.1 |
| Num Word Source # | Since: base-2.1 |
| RealFloat a => Num (Complex a) Source # | Since: base-2.1 |
Defined in Data.Complex Methods (+) :: Complex a -> Complex a -> Complex a Source # (-) :: Complex a -> Complex a -> Complex a Source # (*) :: Complex a -> Complex a -> Complex a Source # negate :: Complex a -> Complex a Source # abs :: Complex a -> Complex a Source # signum :: Complex a -> Complex a Source # fromInteger :: Integer -> Complex a Source # | |
| Num a => Num (Max a) Source # | Since: base-4.9.0.0 |
| Num a => Num (Min a) Source # | Since: base-4.9.0.0 |
| Num a => Num (Identity a) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity Methods (+) :: Identity a -> Identity a -> Identity a Source # (-) :: Identity a -> Identity a -> Identity a Source # (*) :: Identity a -> Identity a -> Identity a Source # negate :: Identity a -> Identity a Source # abs :: Identity a -> Identity a Source # signum :: Identity a -> Identity a Source # fromInteger :: Integer -> Identity a Source # | |
| Num a => Num (Down a) Source # | Since: base-4.11.0.0 |
Defined in GHC.Internal.Data.Ord | |
| Num a => Num (Product a) Source # | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Semigroup.Internal Methods (+) :: Product a -> Product a -> Product a Source # (-) :: Product a -> Product a -> Product a Source # (*) :: Product a -> Product a -> Product a Source # negate :: Product a -> Product a Source # abs :: Product a -> Product a Source # signum :: Product a -> Product a Source # fromInteger :: Integer -> Product a Source # | |
| Num a => Num (Sum a) Source # | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Semigroup.Internal | |
| Integral a => Num (Ratio a) Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real | |
| HasResolution a => Num (Fixed a) Source # | Multiplication is not associative or distributive:
Since: base-2.1 |
Defined in Data.Fixed | |
| Num a => Num (Op a b) Source # | |
Defined in Data.Functor.Contravariant | |
| Num a => Num (Const a b) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const Methods (+) :: Const a b -> Const a b -> Const a b Source # (-) :: Const a b -> Const a b -> Const a b Source # (*) :: Const a b -> Const a b -> Const a b Source # negate :: Const a b -> Const a b Source # abs :: Const a b -> Const a b Source # signum :: Const a b -> Const a b Source # fromInteger :: Integer -> Const a b Source # | |
| (Applicative f, Num a) => Num (Ap f a) Source # | Note that even if the underlying Commutativity:
Additive inverse:
Distributivity:
Since: base-4.12.0.0 |
Defined in GHC.Internal.Data.Monoid | |
| Num (f a) => Num (Alt f a) Source # | Since: base-4.8.0.0 |
Defined in GHC.Internal.Data.Semigroup.Internal | |
| Num (f (g a)) => Num (Compose f g a) Source # | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods (+) :: Compose f g a -> Compose f g a -> Compose f g a Source # (-) :: Compose f g a -> Compose f g a -> Compose f g a Source # (*) :: Compose f g a -> Compose f g a -> Compose f g a Source # negate :: Compose f g a -> Compose f g a Source # abs :: Compose f g a -> Compose f g a Source # signum :: Compose f g a -> Compose f g a Source # fromInteger :: Integer -> Compose f g a Source # | |
quotRemInteger :: Integer -> Integer -> (# Integer, Integer #) Source #
Deprecated: Use integerQuotRem# instead
module GHC.Num.Integer
module GHC.Num.Natural