monad library

Andrew J Bromage
Mon, 28 Jul 2003 10:50:13 +1000

G'day all.

On Fri, Jul 25, 2003 at 12:40:22AM +0200, Iavor Diatchki wrote:

> 1. there are the map* functions for different transformers (mapReader, 
> mapWriter, etc.). does anyone use them for anything?  while there is 
> something common between them, i am not quite sure exactly what it is.

I've used them once, and that was to swap the underlying monad of a
transformer.  It's occasionally handy, for example, when you want your
state to be backtrackable for a small part of your code, to stick a
backtracking monad _under_ the top monad transformer.

I don't think that you can duplicate this behaviour using the other
operations on the monad.

A simple solution would be to introduce this typeclass:

	class (MonadTrans t) => MonadMapTrans t where
	    mapTrans :: (m a -> n b) -> (t m a -> t n b)

I'm not happy with the names, but I'm sure someone can think of
something better.  It might even make sense as a method of MonadTrans

Andrew Bromage