GHC.Num
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:
- 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
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
(+) :: 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
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.10.2/docs/html/libraries/base-4.14.1.0/GHC-Num.html