[Haskell-cafe] Re: Using Collections: ElemsView and KeysView
Jean-Philippe Bernardy
jeanphilippe.bernardy at gmail.com
Mon Aug 20 04:50:34 EDT 2007
foldr on ElemsView is defined as such:
> foldr f i (ElemsView c) = foldr (f . snd) i c
so, for example:
> getElementList = toList . ElemViews
When I designed this code (some years ago), I didn't like the "fold" of Map to
have the type:
> fold :: (a -> b -> b) -> b -> Map k a -> b
This just doesn't make sense if we see maps as a collection of (key, value)
pairs. (Indeed, toList :: Map k a -> [(k, a)])
In order to be consistent, but to provide an easy way to migrate to the new
collection classes I was designing, I provided the ElemViews/KeyViews to
"switch" to the former behaviour on a case by case basis.
This also allows for definining optimized versions of foldr, etc. for each types
that supports "Views", but this was tedious, so I never did it. GHC "RULE"
pragma is probably better suited to the purpose anyway.
As for the lack of documentation, everyone is very welcome to contribute ;)
Cheers,
JP.
More information about the Haskell-Cafe
mailing list