Monadic version of functions for containers (adjustM, updateWithKeyM, etc)

Thomas DuBuisson thomas.dubuisson at gmail.com
Mon Sep 27 18:13:37 EDT 2010


All,

Is there a reason not to have monadic version of the functions in
containers? I've a need for functions of type:

    adjustM :: (Monad m, Ord k) => (a -> m a) -> k -> Map k a -> m (Map k a)
    updateWithKeyM :: (Monad m, Ord k) => (k -> a -> m (Maybe a)) -> k
-> Map k a -> m (Map k a)

where adjustM can be ~ half the cost of separate insert/lookup calls
and would obey the following rule:

    adjustM f k m == liftM (\x -> insert k x m) (f $ lookup k m )

They aren't large, but must be in the containers package due to
opacity of Map/Set/etc.  Perhaps someone can provide a reason for
their omission?  If not then I'll probably start yet-another proposal
in a week or two (once the current containers proposals and my
System.Random proposals have concluded).  Tentatively I expect to make
a patch that includes proper *M functions for Map, Set, IntMap, and
IntSet.

Cheers,
Thomas


More information about the Libraries mailing list