[Haskell-cafe] implementing try for RWST ?

tpledger at ihug.co.nz tpledger at ihug.co.nz
Mon Apr 16 17:46:19 EDT 2007


Jeremy Shaw wrote:
 :
 | However, I think this is buggy, because changes
 | to 's' and 'w' will be lost if 'm' raises an
 | exception.
 :


That's determined by the way you stack your monad
transformers when declaring the type: adding error handling
to a writer monad, or adding writing to an error handling
monad.  For a concrete example, see the result types in the
following.  The first has the Either inside the tuple, and
the second has the tuple inside the Either.

Prelude> :t Control.Monad.Writer.runWriter .
Control.Monad.Error.runErrorT
Control.Monad.Writer.runWriter .
Control.Monad.Error.runErrorT :: Control.Monad.Error.ErrorT
e (Control.Monad.Writer.Writer w) a
-> (Either e a, w)
Prelude> :t either Left Right .
Control.Monad.Writer.runWriterT
either Left Right . Control.Monad.Writer.runWriterT ::
Control.Monad.Writer.WriterT w (Either a) a1 -> Either a
(a1, w)


Regards,
Tom


More information about the Haskell-Cafe mailing list