[Haskell-cafe] ErrorT vs Either
Edward Amsden
eca7215 at cs.rit.edu
Mon May 16 23:12:06 CEST 2011
I suspect it is because the "fail" method for the 'Either' monad
instance makes use of Haskell's error function, since the instance is
defined generally and there is no way to override it for (Either
String a).
On May 16, 2011, Gracjan Polak <gracjanpolak at gmail.com> wrote:
> Control.Monad.Error Prelude> runErrorT (fail "msg") :: IO (Either String Int)
> Left "msg"
ErrorT defines fail to yield a pure value, rather than an exception.
Since ErrorT is a different type than Either (though the runErrorT
method yields an Either), the instances are different.
>
> but
>
> Control.Monad.Error Prelude> (fail "msg") :: (Either String Int)
> *** Exception: msg
The Monad instance for Either is defined generally, e.g. "instance
Monad (Either a) where" so there is know way of typechecking a fail
method that injects a string into "Left" in that case.
--
Edward Amsden
Student
Computer Science
Rochester Institute of Technology
www.edwardamsden.com
More information about the Haskell-Cafe
mailing list