| ... | ... | @@ -14,9 +14,6 @@ Many of the proposals involve additional superclasses, which would be less burde |
|
|
|
|
|
|
|
- [ Standard Haskell Classes](http://www.haskell.org/onlinereport/basic.html#sect6.3) of Haskell 98
|
|
|
|
- [ Standard Prelude](http://www.haskell.org/onlinereport/standard-prelude.html) of Haskell 98
|
|
|
|
- [ Algebraic structures](http://en.wikipedia.org/wiki/Algebraic_structure) in WikiPedia
|
|
|
|
- [ DoCon the Algebraic Domain Constructor](http://www.haskell.org/docon/)
|
|
|
|
- [ Numeric prelude project](http://www.haskell.org/communities/06-2006/html/report.html#numericprelude)
|
|
|
|
|
|
|
|
## Constructor classes
|
|
|
|
|
| ... | ... | @@ -56,79 +53,9 @@ Proposals: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The Haskell 98 numeric classes are adequate for Haskell 98 numeric types, but other mathematical objects do not fit.
|
|
|
|
If the Haskell 98 classes were retained for backwards compatibility, but with a more refined class hierarchy, the change would impact mostly on those defining instances (and these are the people inconvenienced by the current system).
|
|
|
|
Clients of the classes would notice only some more general types.
|
|
|
|
See [NumericClasses](numeric-classes).
|
|
|
|
|
|
|
|
|
|
|
|
### The Num class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
|
|
|
|
|
|
|
|
|
|
- `Eq` and `Show` don't make sense for functions under lifting.
|
|
|
|
- `(*)` doesn't make sense for vectors.
|
|
|
|
- `abs` and `signum` don't make sense for `Complex Integer` (Gaussian integers), vectors, matrices, etc.
|
|
|
|
In general, `abs` and `signum` make it hard to lift `Num` through type constructors.
|
|
|
|
|
|
|
|
|
|
|
|
Proposals:
|
|
|
|
|
|
|
|
|
|
|
|
- A group-like class with `zero`, `(+)` and `negate`/`(-)`.
|
|
|
|
- (Could be further split with a monoid sub-class.)
|
|
|
|
- A ring-like subclass adding `(*)` and `one`/`fromInteger`, with the existing `Num` class as a further subclass.
|
|
|
|
- (Could be further split with a semiring subclass, e.g. for [natural numbers](natural).)
|
|
|
|
|
|
|
|
|
|
|
|
Note that the `Float` and `Double` instances will not satisfy the usual axioms for these structures.
|
|
|
|
|
|
|
|
|
|
|
|
### The Real class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
|
|
|
|
|
|
|
|
|
|
- The class assumes a mapping to `Rational`, but this cannot be defined for structures intermediate between the rationals and reals even though the operations of subclasses make sense for them, e.g. surds, computable reals.
|
|
|
|
|
|
|
|
### The Fractional class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
|
|
|
|
|
|
|
|
|
|
- `(/)`, `recip` and `fromRational` can be lifted to functions, but many of the pre-requisites can't be defined for these.
|
|
|
|
|
|
|
|
|
|
|
|
Proposals:
|
|
|
|
|
|
|
|
|
|
|
|
- Add a division ring-like superclass adding these operations to the ring-like class.
|
|
|
|
(A division ring has the same operations as a field, but does not assume commutative multiplication, allowing structures such as quaternions.)
|
|
|
|
- Add default
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
|
|
|
|
```
|
|
|
|
|
|
|
|
This is independent of all the other proposals.
|
|
|
|
|
|
|
|
### The Integral class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
|
|
|
|
|
|
|
|
|
|
- `div` and `mod` also sense for rationals, polynomials and Gaussian integers, but `Enum` and `toInteger` do not.
|
|
|
|
- `Ord`, `Num(abs, signum)` and `toRational` don't make sense for polynomials and Gaussian integers.
|
|
|
|
- `quot` and `rem` assume an ordering.
|
|
|
|
|
|
|
|
## Other standard classes
|
|
|
|
|
|
|
|
|
| ... | ... | |