Monadic version of functions for containers (adjustM,
felipe.lessa at gmail.com
Mon Sep 27 19:18:06 EDT 2010
On Mon, Sep 27, 2010 at 7:47 PM, Thomas DuBuisson
<thomas.dubuisson at gmail.com> wrote:
> translating this to Functor:
> adjustF f k m ==
> case lookup k m of
> Just x -> fmap (\new -> insert k new m) (f x)
> Nothing -> ??? -- perhaps "pure m" thus adding another
Hmmm, true. With the currenty hierachy, we could have adjustA using
Applicative constraint, although a pointed functor is enough.
> constraint, but how would that be better than Monad for most people?
Having the most general type allows the function to be used in more
places. For example, in an Applicative parser. All Monads are
Applicative, so adjustA is at least as good as adjustM.
More information about the Libraries