Multi-parameter type classes
Brief Explanation
Classes take one or more arguments, becoming relations between types. See also the dilemma they cause.
The mtl package of the Haskell hierarchical libraries utilizes this feature. The base package contains only two such classes:
class HasBounds a => IArray a e class (HasBounds a, Monad m) => MArray a e m
There are FlexibleInstances
instance IArray Array e instance IArray UArray Bool instance IArray UArray Char ...
but no OverlappingInstances.
References
- Type classes: exploring the design space by Simon Peyton Jones, Mark Jones and Erik Meijer, Haskell Workshop 1997.
Tickets
Pros
- offered by GHC and Hugs for years
- express more interesting relationships
Cons
- usually require FlexibleInstances or UndecidableInstances
- often lead to OverlappingInstances and ambiguity, though these can sometimes be avoided using FunctionalDependencies or AssociatedTypes. Examples include container and monad classes.
