wiki:TypeFunctionsExamples

Version 1 (modified by chak, 9 years ago) (diff)

Map example

Examples of Type Functions

The map example from Associated Types with Class in the new form:

data Map k :: * -> *

data Map ()     v = MapUnit (Maybe v)
data Map (a, b) v = MapPair (Map a (Map b v))

We can define operations on indexed maps using a type class whose instances corresponds to the type indexes. Note that a declaration, such as

data Map Int Char = Nonsense

is not acceptable, as it constraints the second argument of Map, which is not a type index, but a parametric argument.