Changes between Version 5 and Version 6 of OverloadedLists
 Timestamp:
 Nov 7, 2012 1:35:07 PM (3 years ago)
Legend:
 Unmodified
 Added
 Removed
 Modified

OverloadedLists
v5 v6 116 116 117 117 One 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 OverloadedListsl where118 the previous section with the {{{ListRep}}} class defined as follows: 119 120 {{{ 121 class ListRep l where 122 122 type Item l 123 123 fromList :: [Item l] > l … … 149 149 expressions and patterns. In other words, {{{:}}} is not overloaded. 150 150 151 The instances of the {{{ OverloadedLists}}} class should satisfy the following151 The instances of the {{{ListRep}}} class should satisfy the following 152 152 property: 153 153 … … 157 157 158 158 The example {{{FromList}}} instances from the previous section can be extended 159 into the {{{ OverloadedLists}}} instances as follows:160 161 {{{ 162 instance OverloadedLists[a] where159 into the {{{ListRep}}} instances as follows: 160 161 {{{ 162 instance ListRep [a] where 163 163 type Item [a] = a 164 164 fromList = id 165 165 toList = id 166 166 167 instance (Ord a) => OverloadedLists(Set a) where167 instance (Ord a) => ListRep (Set a) where 168 168 type Item (Set a) = a 169 169 fromList = Set.fromList 170 170 toList = Set.toList 171 171 172 instance (Ord k) => OverloadedLists(Map k v) where172 instance (Ord k) => ListRep (Map k v) where 173 173 type Item (Map k v) = (k,v) 174 174 fromList = Map.fromList 175 175 toList = Map.toList 176 176 177 instance OverloadedLists(IntMap v) where177 instance ListRep (IntMap v) where 178 178 type Item (IntMap v) = (Int,v) 179 179 fromList = IntMap.fromList 180 180 toList = IntMap.toList 181 181 182 instance OverloadedListsText where182 instance ListRep Text where 183 183 type Item Text = Char 184 184 fromList = Text.pack 185 185 toList = Text.unpack 186 186 187 instance OverloadedLists(Vector a) where187 instance ListRep (Vector a) where 188 188 type Item (Vector a) = a 189 189 fromList = Vector.fromList