broken Monad Either instance?
Christian.Maeder at dfki.de
Mon Nov 28 14:17:04 CET 2011
I was surprised to see my code break with ghc-7, due to changed monad
With ghc-6.12.3 I have:
Prelude> :m Control.Monad.Error
Prelude Control.Monad.Error> fail "Bla" :: Either String ()
Loading package mtl-220.127.116.11 ... linking ... done.
but with ghc-7.0.4 and ghc-7.2.2 I get a fatal exception:
*Main> fail "Bla" :: Either String ()
*** Exception: Bla
I always viewed "Either String" as an alternative to Maybe with a
The instance in ghc-7 comes from Control.Monad.Instances:
instance Monad (Either e) where
return = Right
Left l >>= _ = Left l
Right r >>= k = k r
which indeed uses "error" as default implementation of fail. Is there
(supposed to be) an overlapping "instance Monad (Either String)"
Any comments (or notes) that I missed?
More information about the Libraries