我读过这个问题。以下是已接受答案的引用:
此实例已添加到 ghc 7 附带的 base 4.3.xx 中。同时,您可以
Either
直接使用该实例,或者,如果您Either
用于表示可能失败的内容,则应使用ErrorT
monad 转换器。
我想Either
用于这样的事情:
> (Left "bad thing happened") >>= \x -> Right (x ++ " ...")
Left "bad thing happened"
因此,如果计算的一部分失败,则将其Left
返回。
实际问题是:为什么我应该使用ErrorT
monad 转换器而不是Either
monad?我是 Haskell 的新手,我有点害怕 monad 转换器,尤其是当我已经在其中编写代码时。