NumericPrelude-0.0: An experimental alternative hierarchy of numeric type classesContentsIndex
Algebra.Field
Contents
Class
Properties
Synopsis
class C a => C a where
(/) :: a -> a -> a
recip :: a -> a
fromRational' :: Rational -> a
(^-) :: a -> Integer -> a
(/) :: C a => a -> a -> a
recip :: C a => a -> a
fromRational' :: C a => Rational -> a
(^-) :: C a => a -> Integer -> a
propDivision :: (Eq a, C a, C a) => a -> a -> Property
propReciprocal :: (Eq a, C a, C a) => a -> Property
Class
class C a => C a where

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.

Minimal definition: recip or (/)

Methods
(/) :: a -> a -> a
recip :: a -> a
fromRational' :: Rational -> a
(^-) :: a -> Integer -> a
show/hide Instances
C Double
C Float
C T
C T
Integral a => C (Ratio a)
C a => C (T a)
C a => C (T a)
(C a, C a) => C (T a)
C a => C (T a)
(C a, C a) => C (T a)
(C a, C a) => C (T a)
Divisible a => C (T a)
C a => C (T a)
C a => C (T a)
(Eq a, C a) => C (T a)
C a => C (T a)
C v => C (T a v)
C v => C (T a v)
(Ord i, C a) => C (T i a)
(/) :: C a => a -> a -> a
recip :: C a => a -> a
fromRational' :: C a => Rational -> a
(^-) :: C a => a -> Integer -> a
Properties
propDivision :: (Eq a, C a, C a) => a -> a -> Property
the restriction on the divisor should be isUnit a instead of not (isZero a)
propReciprocal :: (Eq a, C a, C a) => a -> Property
Produced by Haddock version 0.7