Changes between Version 6 and Version 7 of OverloadedLists


Ignore:
Timestamp:
Nov 10, 2012 10:52:07 AM (3 years ago)
Author:
giorgidze
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • OverloadedLists

    v6 v7  
    116116 
    117117One way to overload list patterns is to replace the {{{FromList}}} class from 
    118 the previous section with the {{{ListRep}}} class defined as follows: 
    119  
    120 {{{ 
    121 class ListRep l where 
     118the previous section with the {{{IsList}}} class defined as follows: 
     119 
     120{{{ 
     121class IsList 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 {{{ListRep}}} class should satisfy the following 
     151The instances of the {{{IsList}}} class should satisfy the following 
    152152property: 
    153153 
     
    157157 
    158158The example {{{FromList}}} instances from the previous section can be extended 
    159 into the {{{ListRep}}} instances as follows: 
    160  
    161 {{{ 
    162 instance ListRep [a] where 
     159into the {{{IsList}}} instances as follows: 
     160 
     161{{{ 
     162instance IsList [a] where 
    163163  type Item [a] = a 
    164164  fromList = id 
    165165  toList = id 
    166166 
    167 instance (Ord a) => ListRep (Set a) where 
     167instance (Ord a) => IsList (Set a) where 
    168168  type Item (Set a) = a 
    169169  fromList = Set.fromList 
    170170  toList = Set.toList 
    171171 
    172 instance (Ord k) => ListRep (Map k v) where 
     172instance (Ord k) => IsList (Map k v) where 
    173173  type Item (Map k v) = (k,v) 
    174174  fromList = Map.fromList 
    175175  toList = Map.toList 
    176176 
    177 instance ListRep (IntMap v) where 
     177instance IsList (IntMap v) where 
    178178  type Item (IntMap v) = (Int,v) 
    179179  fromList = IntMap.fromList 
    180180  toList = IntMap.toList 
    181181 
    182 instance ListRep Text where 
     182instance IsList Text where 
    183183  type Item Text = Char 
    184184  fromList = Text.pack 
    185185  toList = Text.unpack 
    186186 
    187 instance ListRep (Vector a) where 
     187instance IsList (Vector a) where 
    188188  type Item (Vector a) = a 
    189189  fromList  = Vector.fromList 
     
    191191  toList = Vector.toList 
    192192}}} 
     193 
     194An alternative name for the {{{IsList}}} class could be {{{ListRep}}} (meaning 
     195representable as list). This is to emphasise that its instances should be 
     196representable as lists, it is not required for them to be lists. 
    193197 
    194198== Further GHC improvements/extensions that may benefit {{{OverloadedLists}}} ==