[Haskell] ANN: monadLib 2.0
iavor.diatchki at gmail.com
Tue Mar 21 13:38:06 EST 2006
On 3/20/06, John Meacham <john at repetae.net> wrote:
> it looks very interesting. I use the mtl extensively in pretty much
> everything I do and am interested in any developments with it. a couple
> whenM,forEach2_, and forEach3_ should have types
> whenM :: Monad m => m Bool -> m a -> m ()
> forEach2_ :: Monad m => [a] -> [b] -> (a -> b -> m c) -> m ()
> forEach3_ :: Monad m => [a] -> [b] -> [c] -> (a -> b -> c -> m d) -> m ()
This is quite reasonable for 'forEach23_', and perhaps by symmetry for 'whenM'.
One thing about 'whenM' however is that to implement it I'll need to
add an extra
'return ()' to the parameter computation. This is probably not a big deal, but
given that most of the time the computation used in 'whenM' is already
of type 'm ()', I wonder if leaving it to the programmer to add the
'return ()' is not a better idea.
What do you think?
> Also, I am curious why some of the names seem to have been changed from
> what the mtl provides, it would be nice if it were mostly a drop in
> replacement as there is substantial mtl code out there.
> mainly I am thinking of
> ask -> getR
> local -> updateR
Some of the other names I changed because I didn't like (e.g. I like
get/set for state, rather then get/put in 'mtl'). These two
(getR,localR) I am not too happy with (also the name of the ReadUpdM
class). I picked them because they resemble the state ones, but
perhaps the 'mtl' ones are better, although I am not sure about that.
Note however that 'monadLib' is not a drop in replacement for 'mtl',
as other things differ as well, for example 'monadLib' has a different
monad class hierarchy.
> also, it looks like some of the very useful utility routines in the
> current mtl such as 'asks' arn't included.
I didn't add 'asks' because to me it seems redundant.
Instead of "asks field" I write "field # getR" (or 'field # ask' if we
were to use the 'mtl' terminology). Are there other useful methods
that I missed?
> though, I would be very happy to shorten 'Identity' to 'Id'. having a
> standard identity newtype is surprising useful all over the place, even
> when not used as a monad.
That's interesting to know. I have not used it for anything else, do
you have examples of how you use it?
> deriving Typeable for everything would be good too.
I have never used 'Typeable', but perhaps I will take a look. I would
like 'monadLib' to stay simple, but if people use 'Typeable' on
monadic computations I could probably add some instances. Are there
any examples of when it is useful to do things like that? Does Hugs
> Also, it looks like some of your monads overlap with what is provided by
> the Applicative (Idiom) and friends classes to be included in the next
> version of ghc, perhaps you can make a version of monadLib that builds
> on those?
I am aware of that, and once they are released I will probably make
use of them, because I think that they have some nice ideas. In the
mean time however 'monadLib' provides 'Monad.ForEach' and
Thanks for the comments!
More information about the Libraries