Changes between Version 1 and Version 2 of TypeFunctionsExamples


Ignore:
Timestamp:
Aug 15, 2006 9:34:42 PM (8 years ago)
Author:
chak
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TypeFunctionsExamples

    v1 v2  
    33The map example from ''Associated Types with Class'' in the new form: 
    44{{{ 
    5 data Map k :: * -> * 
     5data family Map k :: * -> * 
    66 
    7 data Map ()     v = MapUnit (Maybe v) 
    8 data Map (a, b) v = MapPair (Map a (Map b v)) 
     7data instance Map ()     v = MapUnit (Maybe v) 
     8data instance Map (a, b) v = MapPair (Map a (Map b v)) 
    99}}} 
    1010We can define operations on indexed maps using a type class whose instances corresponds to the type indexes.  Note that a declaration, such as 
    1111{{{ 
    12 data Map Int Char = Nonsense 
     12data instance Map Int Char = Nonsense 
    1313}}} 
    1414is not acceptable, as it constraints the second argument of `Map`, which is not a type index, but a parametric argument.