Copyright | (c) The University of Glasgow 1994-2002 |
---|---|
License | see libraries/base/LICENSE |
Maintainer | [email protected] |
Stability | internal |
Portability | non-portable (GHC Extensions) |
Safe Haskell | Trustworthy |
Language | Haskell2010 |
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:
(+)
(x + y) + z
= x + (y + z)
(+)
x + y
= y + x
fromInteger 0
is the additive identityx + fromInteger 0
= x
negate
gives the additive inversex + negate x
= fromInteger 0
(*)
(x * y) * z
= x * (y * z)
fromInteger 1
is the multiplicative identityx * fromInteger 1
= x
and fromInteger 1 * x
= x
(*)
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.
(+) :: 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
.
subtract :: Num a => a -> a -> a Source
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.
module GHC.Integer
module GHC.Natural
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.8.3/docs/html/libraries/base-4.13.0.0/GHC-Num.html