broken Monad Either instance?
Christian Maeder
Christian.Maeder at dfki.de
Mon Nov 28 14:17:04 CET 2011
Hi,
I was surprised to see my code break with ghc-7, due to changed monad
instances:
With ghc-6.12.3 I have:
Prelude> :m Control.Monad.Error
Prelude Control.Monad.Error> fail "Bla" :: Either String ()
Loading package mtl-1.1.0.2 ... linking ... done.
Left "Bla"
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
failure message.
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)"
somewhere else?
Any comments (or notes) that I missed?
Cheers Christian
More information about the Libraries
mailing list