| Safe Haskell | None |
|---|---|
| Language | Haskell98 |
GHC.Real_LHAssumptions
Documentation
class (Real a, Enum a) => Integral a where #
Integral numbers, supporting integer division.
The Haskell Report defines no laws for Integral. However, Integral instances are customarily expected to define a Euclidean domain and have the following properties for the div/mod and quot/rem pairs, given suitable Euclidean functions f and g:
x=y * quot x y + rem x ywithrem x y=fromInteger 0org (rem x y)<g yx=y * div x y + mod x ywithmod x y=fromInteger 0orf (mod x y)<f y
An example of a suitable Euclidean function, for Integer's instance, is abs.
In addition, toInteger should be total, and fromInteger should be a left inverse for it, i.e. fromInteger (toInteger i) = i.
Methods
quot :: a -> a -> a infixl 7 #
Integer division truncated toward zero.
WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.
Integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.
Integer division truncated toward negative infinity.
WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.
Integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.
WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.
WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.
Conversion to Integer.
Instances
class Num a => Fractional a where #
Fractional numbers, supporting real division.
The Haskell Report defines no laws for Fractional. However, ( and +)( are customarily expected to define a division ring and have the following properties:*)
recipgives the multiplicative inversex * recip x=recip x * x=fromInteger 1- Totality of
toRational toRationalis total- Coherence with
toRational - if the type also implements
Real, thenfromRationalis a left inverse fortoRational, i.e.fromRational (toRational i) = i
Note that it isn't customarily expected that a type instance of Fractional implement a field. However, all instances in base do.
Minimal complete definition
fromRational, (recip | (/))
Methods
Fractional division.
Reciprocal fraction.
fromRational :: Rational -> a #
Conversion from a Rational (that is ). A floating literal stands for an application of Ratio IntegerfromRational to a value of type Rational, so such literals have type (.Fractional a) => a
Instances
| Fractional CDouble | |
| Fractional CFloat | |
| RealFloat a => Fractional (Complex a) | Since: base-2.1 |
| Fractional a => Fractional (Identity a) | @since base-4.9.0.0 |
| Fractional a => Fractional (Down a) | @since base-4.14.0.0 |
| Integral a => Fractional (Ratio a) | @since base-2.0.1 |
| HasResolution a => Fractional (Fixed a) | Since: base-2.1 |
| Fractional a => Fractional (Op a b) | |
| Fractional a => Fractional (Const a b) | @since base-4.9.0.0 |
| Fractional (f (g a)) => Fractional (Compose f g a) | Since: base-4.20.0.0 |