Copyright | (c) The University of Glasgow 1994-2002 |
---|---|
License | see libraries/base/LICENSE |
Maintainer | cvs-ghc@haskell.org |
Stability | internal |
Portability | non-portable (GHC Extensions) |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
GHC.Num
Synopsis
- class Num a where
- subtract :: Num a => a -> a -> a
- module GHC.Integer
- module GHC.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 + x
is the additive identityfromInteger
0x + fromInteger 0
=x
negate
gives the additive inversex + negate x
=fromInteger 0
- Associativity of
(
*
) (x * y) * z
=x * (y * z)
is the multiplicative identityfromInteger
1x * fromInteger 1
=x
andfromInteger 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.
Methods
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 #
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 Double # | Note that due to the presence of
Also note that due to the presence of -0,
Since: base-2.1 |
Num Float # | Note that due to the presence of
Also note that due to the presence of -0,
Since: base-2.1 |
Num Int # | Since: base-2.1 |
Num Int8 # | Since: base-2.1 |
Num Int16 # | Since: base-2.1 |
Num Int32 # | Since: base-2.1 |
Num Int64 # | Since: base-2.1 |
Num Integer # | Since: base-2.1 |
Num Natural # | Note that Since: base-4.8.0.0 |
Num Word # | Since: base-2.1 |
Num Word8 # | Since: base-2.1 |
Num Word16 # | Since: base-2.1 |
Num Word32 # | Since: base-2.1 |
Num Word64 # | Since: base-2.1 |
Num IntPtr # | |
Num WordPtr # | |
Num CUIntMax # | |
Num CIntMax # | |
Num CUIntPtr # | |
Num CIntPtr # | |
Num CSUSeconds # | |
Defined in Foreign.C.Types Methods (+) :: CSUSeconds -> CSUSeconds -> CSUSeconds # (-) :: CSUSeconds -> CSUSeconds -> CSUSeconds # (*) :: CSUSeconds -> CSUSeconds -> CSUSeconds # negate :: CSUSeconds -> CSUSeconds # abs :: CSUSeconds -> CSUSeconds # signum :: CSUSeconds -> CSUSeconds # fromInteger :: Integer -> CSUSeconds # | |
Num CUSeconds # | |
Defined in Foreign.C.Types | |
Num CTime # | |
Num CClock # | |
Num CSigAtomic # | |
Defined in Foreign.C.Types Methods (+) :: CSigAtomic -> CSigAtomic -> CSigAtomic # (-) :: CSigAtomic -> CSigAtomic -> CSigAtomic # (*) :: CSigAtomic -> CSigAtomic -> CSigAtomic # negate :: CSigAtomic -> CSigAtomic # abs :: CSigAtomic -> CSigAtomic # signum :: CSigAtomic -> CSigAtomic # fromInteger :: Integer -> CSigAtomic # | |
Num CWchar # | |
Num CSize # | |
Num CPtrdiff # | |
Num CDouble # | |
Num CFloat # | |
Num CBool # | |
Num CULLong # | |
Num CLLong # | |
Num CULong # | |
Num CLong # | |
Num CUInt # | |
Num CInt # | |
Num CUShort # | |
Num CShort # | |
Num CUChar # | |
Num CSChar # | |
Num CChar # | |
Num Fd # | |
Num CKey # | |
Num CId # | |
Num CFsFilCnt # | |
Defined in System.Posix.Types | |
Num CFsBlkCnt # | |
Defined in System.Posix.Types | |
Num CClockId # | |
Num CBlkCnt # | |
Num CBlkSize # | |
Num CRLim # | |
Num CTcflag # | |
Num CSpeed # | |
Num CCc # | |
Num CUid # | |
Num CNlink # | |
Num CGid # | |
Num CSsize # | |
Num CPid # | |
Num COff # | |
Num CMode # | |
Num CIno # | |
Num CDev # | |
Integral a => Num (Ratio a) # | Since: base-2.0.1 |
Num a => Num (Down a) # | Since: base-4.11.0.0 |
Num a => Num (Product a) # | Since: base-4.7.0.0 |
Defined in Data.Semigroup.Internal | |
Num a => Num (Sum a) # | Since: base-4.7.0.0 |
Num a => Num (Identity a) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Identity | |
Num a => Num (Max a) # | Since: base-4.9.0.0 |
Num a => Num (Min a) # | Since: base-4.9.0.0 |
HasResolution a => Num (Fixed a) # | Since: base-2.1 |
RealFloat a => Num (Complex a) # | Since: base-2.1 |
Num a => Num (Op a b) # | |
Num (f a) => Num (Alt f a) # | Since: base-4.8.0.0 |
(Applicative f, Num a) => Num (Ap f a) # | Since: base-4.12.0.0 |
Num a => Num (Const a b) # | Since: base-4.9.0.0 |
Defined in Data.Functor.Const |
module GHC.Integer
module GHC.Natural