Proposal: Value strict versions of containers
Edward Z. Yang
ezyang at MIT.EDU
Sat May 21 19:19:34 CEST 2011
As it stands, we have strict functions for certain operations, such as
insertWith. But this current selection is somewhat arbitrary. For
illustrative purposes, here are other functions that ought to be strictified in
IntMap, because there is no easy way for a user to implement them.
Data.IntMap
insertLookupWithKey
adjust
adjustWithKey
update
updateWithKey
updateLookupWithKey
alter
updateMinWithKey
updateMaxWithKey
updateMax
updateMin
map
mapWithKey
There are also some functions that could be implemented by the user,
assuming that IntMap always forces the outer structure returned
by the combining functions here, but are tricky to do so.
mapAccum
mapAccumWithKey
mapAccumRWithKey
mapAccumL
mapMaybe
mapMaybeWithKey
mapEither
mapEitherWithKey
Since there are so many of these functions, I propose we introduce Lazy and
Strict versions of IntMap. We should also carefully document operations on the
IntMap that are strict on all values; for example, filter. Similar changes
should be made to Data.Map.
There is also a companion proposal: Regardless of whether or not we implement
Strict and Lazy versions of IntMap, we should implement all of these strict
versions of functions, because are not easy for end-users to implement. A
counter-proposal is, if we split out Strict and Lazy IntMap, we should
*remove* all strict functions from the lazy map, on grounds that selective
strictness can be implemented with an extra layer of indirection on the Strict
IntMap.
Commentary: I favor separate value strict and value lazy maps, and also believe
that insertWith' and friends should be deprecated from the lazy versions. I
don't think reimplementing all of these functions to be strict is a good idea,
on code duplication and API clutter reasons. Remember: at the cost of one
layer of indirection, you can be selectively lazy using IntMap (Lazy a).
Discussion period: 3 weeks
Cheers,
Edward
More information about the Libraries
mailing list