Safe Haskell | None |
---|---|
Language | Haskell98 |
Class
Field again corresponds to a commutative ring. Division is partially defined and satisfies
not (isZero b) ==> (a * b) / b === a not (isZero a) ==> a * recip a === one
when it is defined. To safely call division, the program must take type-specific action; e.g., the following is appropriate in many cases:
safeRecip :: (Integral a, Eq a, Field.C a) => a -> Maybe a safeRecip x = let (q,r) = one `divMod` x in toMaybe (isZero r) q
Typical examples include rationals, the real numbers, and rational functions (ratios of polynomial functions). An instance should be typically declared only if most elements are invertible.
Actually, we have also used this type class for non-fields
containing lots of units,
e.g. residue classes with respect to non-primes and power series.
So the restriction not (isZero a)
must be better isUnit a
.
Instances
C Double Source # | |
C Float Source # | |
C T Source # | |
C T Source # | |
C T Source # | |
Integral a => C (Ratio a) Source # | |
RealFloat a => C (Complex a) Source # | |
(Ord a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
Fractional a => C (T a) Source # | |
C a => C (T a) Source # | |
(Eq a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
(C a, C a) => C (T a) Source # | |
(C a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
C a => C (T a) Source # | |
(C a, C a) => C (T a) Source # | |
C a => C (T a) Source # | |
C v => C (T a v) Source # | |
(IsScalar u, C a) => C (T u a) Source # | |
(Ord i, C a) => C (T i a) Source # | |
C v => C (T a v) Source # | |
fromRational' :: C a => Rational -> a Source #
fromRational :: C a => Rational -> a Source #
Needed to work around shortcomings in GHC.