@@ -15,9 +15,27 @@ import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+))
15
15
16
16
-- | The `Field` class is for types that are (commutative) fields.
17
17
-- |
18
- -- | `Field`s are exactly `EuclideanRing` + `CommutativeRing` so this class
19
- -- | exists as a convenience, so a single constraint can be used when field-like
20
- -- | behaviour is expected.
21
- class (EuclideanRing a , CommutativeRing a ) <= Field a
18
+ -- | Mathematically, a field is a ring which is commutative and in which every
19
+ -- | nonzero element has a multiplicative inverse; these conditions correspond
20
+ -- | to the `CommutativeRing` and `DivisionRing` classes in PureScript
21
+ -- | respectively. However, the `Field` class has `EuclideanRing` and
22
+ -- | `DivisionRing` as superclasses, which seems like a stronger requirement
23
+ -- | (since `CommutativeRing` is a superclass of `EuclideanRing`). In fact, it
24
+ -- | is not stronger, since any type which has law-abiding `CommutativeRing`
25
+ -- | and `DivisionRing` instances permits exactly one law-abiding
26
+ -- | `EuclideanRing` instance. We use a `EuclideanRing` superclass here in
27
+ -- | order to ensure that a `Field` constraint on a function permits you to use
28
+ -- | `div` on that type, since `div` is a member of `EuclideanRing`.
29
+ -- |
30
+ -- | This class has no laws or members of its own; it exists as a convenience,
31
+ -- | so a single constraint can be used when field-like behaviour is expected.
32
+ -- |
33
+ -- | This module also defines a single `Field` instance for any type which has
34
+ -- | both `EuclideanRing` and `DivisionRing` instances. Any other instance
35
+ -- | would overlap with this instance, so no other `Field` instances should be
36
+ -- | defined in libraries. Instead, simply define `EuclideanRing` and
37
+ -- | `DivisionRing` instances, and this will permit your type to be used with a
38
+ -- | `Field` constraint.
39
+ class (EuclideanRing a , DivisionRing a ) <= Field a
22
40
23
- instance fieldNumber :: (EuclideanRing a , CommutativeRing a ) => Field a
41
+ instance field :: (EuclideanRing a , DivisionRing a ) => Field a
0 commit comments