Issues with 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 or something similar, but such features are not yet implemented.
References
- Standard Haskell Classes of Haskell 98
- Standard Prelude of Haskell 98
Constructor classes
The Functor class
Proposal:
- Add instances for
((->) a)
,((,) a)
andEither a
.
The Monad class
Issues:
- Monads are really functors, but programmers can't always assume that
fmap
is defined for them, and so must useliftM
instead. Similarly, code parameterized byFunctor
cannot be used with monads. - The
fail
method was added to the class in Haskell 98 to implement pattern match failure indo
expressions. However the assumption that errors are strings can be problematic (e.g. cf theError
class in Control.Monad.Error, or for internationalization).
Proposals:
- Add instance for
((->) a)
. - Make
Functor
a superclass ofMonad
. This would impose an extra burden on those who just want to define aMonad
. - Make
join
a method ofMonad
, interdefined with(>>=)
. - A more extreme step down this road would be to interpose the new Applicative class between
Functor
andMonad
, with corresponding renaming of methods.
Numbers
See NumericClasses.
Other standard classes
The Read class
See ReadClass.
The Enum class
Issues:
-
succ
andpred
are unused. - The default definitions of
enum
* would make more sense iftoEnum
andfromEnum
usedInteger
instead ofInt
. - Some doubt that it makes sense to have
Float
andDouble
instances. - It is wierd that
[0,3..20]::[Rational]
includes21
.
The Ix class
Issues:
- There is no portable way to report indexing errors accurately.
Proposal:
- Make
Show
a superclass ofIx
, so that the offending index and range can be shown in exceptions. (All instances ofIx
in thebase
package are also instances ofShow
.)
The Bits class
Issues:
- The
Num
superclass may unduly restrict instances. The only thing actually needed fromNum
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
Issues:
- Some interfaces require clients to manage the memory for objects, but to treat them abstractly. In such cases one wants to define
sizeOf
andalignment
(to usemalloc
oralloca
), but notpeek
orpoke
.