
2 Dec
2009
2 Dec
'09
1:16 p.m.
I feel that Data.Set and Data.Map should be working together more closely. For example you can already get the keyset of a Map, but the `other way' is not built-in. I mean a function with a signature like Ord k => Data.Set.Set k -> (k->v) -> Data.Map.Map k v You can implement it in O(n):
assoc :: (a->b) -> [a] -> [(a,b)] assoc f = map (\x -> (x, f x))
mapToMap :: Ord k => (k -> v) -> Data.Set.Set k -> Data.Map.Map k v mapToMap f = Data.Map.fromAscList . assoc f . Data.Set.toAscList
The name assoc alludes to the assoc-lists of Lisp.