Multi-parameter type class
|(4 intermediate revisions by 4 users not shown)|
Revision as of 17:19, 21 December 2012
Basically, type classes which can take multiple arguments, such as:
class Monad m => VarMonad m v where new :: a -> m (v a) get :: v a -> m a put :: v a -> a -> m () instance VarMonad IO IORef where ... instance VarMonad (ST s) (STRef s) where ...
If you think of a single-parameter type class as a set of types, then a multi-parameter type class is a relation between types.
Naive use of MPTCs may result in ambiguity, so functional dependencies were developed as a method of resolving that ambiguity, declaring that some subset of the parameters is sufficient to determine the values of the others.
Some uses of MPTCs with functional dependencies can be replaced with type families.