Skip to content

Commit 56bf5b8

Browse files
authored
Merge pull request #173 from purescript/field-class-tweaks
Update `Field` (refs #132)
2 parents 4507d01 + 9247e06 commit 56bf5b8

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/Data/Field.purs

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,27 @@ import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+))
1515

1616
-- | The `Field` class is for types that are (commutative) fields.
1717
-- |
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
2240

23-
instance fieldNumber :: (EuclideanRing a, CommutativeRing a) => Field a
41+
instance field :: (EuclideanRing a, DivisionRing a) => Field a

0 commit comments

Comments
 (0)