November 2015
Intermediate to advanced
166 pages
3h 14m
English
There are several ways in which type-classes can be generalized further. In this section, we will focus on extending the number of type parameters from one to many. The extension to multiparameter type-classes demands that we specify relations between type parameters by way of functional dependencies.
We can view regular type-classes (for example Ord a, Monad a, and so on.) as a way to specify a set of types. Multiparameter classes, on the other hand, specify a set of type relations. For example, the Coerce type-class specifies a relation between two type parameters:
class Coerce a b where coerce :: a -> b instance Coerce Int String where coerce = show instance Coerce Int [Int] where coerce x = ...
Read now
Unlock full access