[Haskell-cafe] Using MonadError within other Monads

Andrew Pimlott andrew at pimlott.net
Mon Dec 19 15:30:01 EST 2005


On Mon, Dec 19, 2005 at 10:21:36PM +1300, Karl Grapone wrote:
> I still find monadic signatures a little confusing, I believe ghci
> was, at some point, deriving types for f or g that had MonadError in
> place of Either String, so I'll have to think carefully about why it
> is so different from the ErrorT type you show below.

You used throwError, which is a MonadError method, so it's not
surprising to get a message about MonadError.  Regarding ErrorT...

> At one point I was playing with types like 'Either String (IO
> String)', which to me seems very similar to the ErrorT type. 

Actually, your type

    IO (Either String String)

is the same as

    ErrorT String IO String

except for the newtype wrapper.  The big difference in use is that the
"ErrorT String IO" Monad instance combines the monad structures of IO
and Either.  So you won't need nested do's, and a few other things will
have to change (and you might have to think a bit about mapErrs).

> Intuitively they don't seem like they'd be correct... I feel like
> determining that there is an error involves interaction with the
> outside world, consequently the error part should be inside the IO
> monad.

You're correct about that--"Either String (IO String)" is not a monad.

Andrew


More information about the Haskell-Cafe mailing list