Skip to content

Update Field (refs #132) #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions src/Data/Field.purs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,27 @@ import Data.Semiring (class Semiring, add, mul, one, zero, (*), (+))

-- | The `Field` class is for types that are (commutative) fields.
-- |
-- | `Field`s are exactly `EuclideanRing` + `CommutativeRing` so this class
-- | exists as a convenience, so a single constraint can be used when field-like
-- | behaviour is expected.
class (EuclideanRing a, CommutativeRing a) <= Field a
-- | Mathematically, a field is a ring which is commutative and in which every
-- | nonzero element has a multiplicative inverse; these conditions correspond
-- | to the `CommutativeRing` and `DivisionRing` classes in PureScript
-- | respectively. However, the `Field` class has `EuclideanRing` and
-- | `DivisionRing` as superclasses, which seems like a stronger requirement
-- | (since `CommutativeRing` is a superclass of `EuclideanRing`). In fact, it
-- | is not stronger, since any type which has law-abiding `CommutativeRing`
-- | and `DivisionRing` instances permits exactly one law-abiding
-- | `EuclideanRing` instance. We use a `EuclideanRing` superclass here in
-- | order to ensure that a `Field` constraint on a function permits you to use
-- | `div` on that type, since `div` is a member of `EuclideanRing`.
-- |
-- | This class has no laws or members of its own; it exists as a convenience,
-- | so a single constraint can be used when field-like behaviour is expected.
-- |
-- | This module also defines a single `Field` instance for any type which has
-- | both `EuclideanRing` and `DivisionRing` instances. Any other instance
-- | would overlap with this instance, so no other `Field` instances should be
-- | defined in libraries. Instead, simply define `EuclideanRing` and
-- | `DivisionRing` instances, and this will permit your type to be used with a
-- | `Field` constraint.
class (EuclideanRing a, DivisionRing a) <= Field a

instance fieldNumber :: (EuclideanRing a, CommutativeRing a) => Field a
instance field :: (EuclideanRing a, DivisionRing a) => Field a