Changes between Version 5 and Version 6 of OverloadedLists


Ignore:
Timestamp:
Nov 7, 2012 1:35:07 PM (3 years ago)
Author:
giorgidze
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OverloadedLists

    v5 v6  
    116116
    117117One way to overload list patterns is to replace the {{{FromList}}} class from
    118 the previous section with the {{{OverloadedLists}}} class defined as follows:
    119 
    120 {{{
    121 class OverloadedLists l where
     118the previous section with the {{{ListRep}}} class defined as follows:
     119
     120{{{
     121class ListRep l where
    122122  type Item l
    123123  fromList  :: [Item l] -> l
     
    149149expressions and patterns. In other words, {{{:}}} is not overloaded.
    150150
    151 The instances of the {{{OverloadedLists}}} class should satisfy the following
     151The instances of the {{{ListRep}}} class should satisfy the following
    152152property:
    153153
     
    157157
    158158The example {{{FromList}}} instances from the previous section can be extended
    159 into the {{{OverloadedLists}}} instances as follows:
    160 
    161 {{{
    162 instance OverloadedLists [a] where
     159into the {{{ListRep}}} instances as follows:
     160
     161{{{
     162instance ListRep [a] where
    163163  type Item [a] = a
    164164  fromList = id
    165165  toList = id
    166166
    167 instance (Ord a) => OverloadedLists (Set a) where
     167instance (Ord a) => ListRep (Set a) where
    168168  type Item (Set a) = a
    169169  fromList = Set.fromList
    170170  toList = Set.toList
    171171
    172 instance (Ord k) => OverloadedLists (Map k v) where
     172instance (Ord k) => ListRep (Map k v) where
    173173  type Item (Map k v) = (k,v)
    174174  fromList = Map.fromList
    175175  toList = Map.toList
    176176
    177 instance OverloadedLists (IntMap v) where
     177instance ListRep (IntMap v) where
    178178  type Item (IntMap v) = (Int,v)
    179179  fromList = IntMap.fromList
    180180  toList = IntMap.toList
    181181
    182 instance OverloadedLists Text where
     182instance ListRep Text where
    183183  type Item Text = Char
    184184  fromList = Text.pack
    185185  toList = Text.unpack
    186186
    187 instance OverloadedLists (Vector a) where
     187instance ListRep (Vector a) where
    188188  type Item (Vector a) = a
    189189  fromList  = Vector.fromList