|
|
# Issues with Standard Classes
|
|
# Issues with Standard Classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
This page collects issues and proposals for the standard classes.
|
|
This page collects issues and proposals for the standard classes.
|
|
|
Many of the proposals involve additional superclasses, which would be less burdensome with [class aliases](https://gitlab.haskell.org//haskell/prime/issues/101) or something similar, but such features are not yet implemented.
|
|
Many of the proposals involve additional superclasses, which would be less burdensome with [class aliases](https://gitlab.haskell.org//haskell/prime/issues/101) or something similar, but such features are not yet implemented.
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
|
- [ Standard Haskell Classes](http://www.haskell.org/onlinereport/basic.html#sect6.3) of Haskell 98
|
|
## The Read class
|
|
|
- [ Standard Prelude](http://www.haskell.org/onlinereport/standard-prelude.html) of Haskell 98
|
|
|
|
|
|
|
|
|
|
## Constructor classes
|
|
|
|
|
|
|
|
|
|
### The Functor class
|
|
|
|
|
|
|
|
|
|
|
See [ReadClass](read-class).
|
|
|
|
|
|
|
|
Proposal:
|
|
|
|
|
|
|
|
|
|
- Add instances for `((->) a)`, `((,) a)` and `Either a`.
|
|
## The Enum class
|
|
|
|
|
|
|
|
### The Monad class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
Issues:
|
|
|
|
|
|
|
|
|
|
|
|
|
- `succ` and `pred` are unused.
|
|
|
|
- The default definitions of `enum`\* would make more sense if `toEnum` and `fromEnum` used `Integer` instead of `Int`.
|
|
|
|
|
|
|
|
## The Monad class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
|
|
|
|
|
|
|
|
|
- Monads are really functors, but programmers can't always assume that `fmap` is defined for them, and so must use `liftM` instead.
|
|
- Monads are really functors, but programmers can't always assume that `fmap` is defined for them, and so must use `liftM` instead.
|
|
|
Similarly, code parameterized by `Functor` cannot be used with monads.
|
|
Similarly, code parameterized by `Functor` cannot be used with monads.
|
|
|
- The `fail` method was added to the class in Haskell 98 to implement pattern match failure in `do` expressions.
|
|
|
|
|
However the assumption that errors are strings can be problematic (e.g. cf the `Error` class in [ Control.Monad.Error](http://www.haskell.org/ghc/docs/6.4-latest/html/libraries/mtl/Control-Monad-Error.html), or for internationalization).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Proposals:
|
|
Proposals:
|
|
|
|
|
|
|
|
- Add instance for `((->) a)`.
|
|
|
|
|
- Make `Functor` a superclass of `Monad`.
|
|
- Make `Functor` a superclass of `Monad`.
|
|
|
This would impose an extra burden on those who just want to define a `Monad`.
|
|
This would impose an extra burden on those who just want to define a `Monad`.
|
|
|
- Make `join` a method of `Monad`, interdefined with `(>>=)`.
|
|
- Make `join` a method of `Monad`, interdefined with `(>>=)`.
|
| ... | @@ -40,49 +45,82 @@ Proposals: |
... | @@ -40,49 +45,82 @@ Proposals: |
|
|
## Numbers
|
|
## Numbers
|
|
|
|
|
|
|
|
|
|
|
|
|
See [NumericClasses](numeric-classes).
|
|
|
|
|
|
|
|
|
|
## Other standard classes
|
|
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 also:
|
|
|
|
|
|
|
|
### The Read class
|
|
|
|
|
|
|
|
|
|
|
- [ DoCon the Algebraic Domain Constructor](http://haskell.org/docon/)
|
|
|
|
- [ Numeric prelude project](http://haskell.org/communities/06-2006/html/report.html#numericprelude)
|
|
|
|
|
|
|
|
See [ReadClass](read-class).
|
|
### The Num class
|
|
|
|
|
|
|
|
### The Enum class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
Issues:
|
|
|
|
|
|
|
|
- `succ` and `pred` are unused.
|
|
|
|
|
- The default definitions of `enum`\* would make more sense if `toEnum` and `fromEnum` used `Integer` instead of `Int`.
|
|
|
|
|
- Some doubt that it makes sense to have `Float` and `Double` instances.
|
|
|
|
|
- It is wierd that `[0,3..20]::[Rational]` includes `21`.
|
|
|
|
|
|
|
|
|
|
### The Ix class
|
|
- `Eq` and `Show` don't make sense functions under lifting.
|
|
|
|
- `(*)` doesn't make sense for vectors.
|
|
|
|
- `abs` and `signum` don't make sense for `Complex Integer` (Gaussian integers), vectors, matrices, etc.
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
Proposals:
|
|
|
|
|
|
|
|
- There is no portable way to report indexing errors accurately.
|
|
|
|
|
|
|
|
|
|
|
- a group-like class with `zero`, `(+)` and `negate`/`(-)`.
|
|
|
|
- a ring-like subclass adding `(*)` and `one`/`fromInteger`, with the existing `Num` class as a further subclass.
|
|
|
|
|
|
|
|
Proposal:
|
|
|
|
|
|
|
|
|
|
- Make `Show` a superclass of `Ix`, so that the offending index and range can be shown in exceptions.
|
|
Note that the `Float` and `Double` instances will not satisfy the usual axioms for these structures.
|
|
|
(All instances of `Ix` in the `base` package are also instances of `Show`.)
|
|
|
|
|
|
|
|
|
|
### The Integral class
|
|
|
|
|
|
|
|
### The Bits class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
Issues:
|
|
|
|
|
|
|
|
- The `Num` superclass may unduly restrict instances. The only thing actually needed from `Num` is 0.
|
|
|
|
|
- The `bitSize` method is not defined for all instances, and there is no general way to test whether it can be safely called.
|
|
|
|
|
|
|
|
|
|
### The Storable class
|
|
- `div` and `mod` also sense for rationals and polynomials, but `Ord`, `Num` and `toInteger` (and `toRational` for polynomials) don't.
|
|
|
|
- `quot` and `rem` assume an ordering.
|
|
|
|
|
|
|
|
### The Fractional class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
Issues:
|
|
|
|
|
|
|
|
- Some interfaces require clients to manage the memory for objects, but to treat them abstractly. In such cases one wants to define `sizeOf` and `alignment` (to use `malloc` or `alloca`), but not `peek` or `poke`. |
|
|
|
|
|
- `(/)` can be lifted to functions, but many of the pre-requisites can't be defined for these.
|
|
|
|
|
|
|
|
|
|
|
|
Proposals:
|
|
|
|
|
|
|
|
|
|
|
|
- Add a field-like superclass adding these operations to the ring-like class.
|
|
|
|
- Add default
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
fromRational x = fromInteger (numerator x) / fromInteger (denominator x)
|
|
|
|
```
|
|
|
|
|
|
|
|
This is independent of all the other proposals.
|
|
|
|
|
|
|
|
## The Ix class
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Issues:
|
|
|
|
|
|
|
|
|
|
|
|
- There is no portable way to report indexing errors accurately.
|
|
|
|
|
|
|
|
|
|
|
|
Proposal:
|
|
|
|
|
|
|
|
|
|
|
|
- Make `Show` a superclass of `Ix`, so that the offending index and range can be shown in exceptions.
|
|
|
|
(All instances of `Ix` in the `base` package are also instances of `Show`.) |