instance Monad Either?

According to this http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-erro... Either is an instance of class Monad, but when I try to use the do notation I get a compiler error. What's going on? E.

On Dec 20, 2007 1:35 PM, Eric
According to this < http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-erro...
Either is an instance of class Monad, but when I try to use the do notation I get a compiler error. What's going on?
It would help if you'd provide an example of how you're trying to use it and what the error message is. Thanks! It's actually Either String, not Either, that can be an instance of Monad.

On 12/20/07, Eric
According to this http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-erro... Either is an instance of class Monad, but when I try to use the do notation I get a compiler error. What's going on?
Near the bottom of that page is a comment by Luis Cabellos. Does that comment bring you any closer to enlightenment? Cheers! --Tom Phoenix

Tom Phoenix wrote:
On 12/20/07, Eric
wrote: According to this http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-erro... Either is an instance of class Monad, but when I try to use the do notation I get a compiler error. What's going on?
Near the bottom of that page is a comment by Luis Cabellos. Does that comment bring you any closer to enlightenment?
It works now. Thanks! E.

Eric wrote:
According to this http://www.randomhacks.net/articles/2007/03/10/haskell-8-ways-to-report-erro... Either is an instance of class Monad, but when I try to use the do notation I get a compiler error. What's going on?
Try to import Control.Monad.Error to get a Monad instance for Either. Actually, the instance is for (Error a => Either a), So it's more like the 5. aproach on that page. But since there is an instance Error String you can use (Either String) as a Monad (or a MonadError): import Control.Monad.Error test1 :: Either String Int test1 = do [x, y, z] <- return [3] return 42 test2 :: MonadError e m => m Int test2 = do [x, y, z] <- return [3] return 42 *Main> test Left "Pattern match failure in do expression at test.hs:5:2-10" *Main> test2 :: Either String Int Left "Pattern match failure in do expression at test.hs:11:2-10" *Main> test2 :: IO Int *** Exception: user error (Pattern match failure in do expression at test.hs:11:2-10) Tillmann
participants (4)
-
Eric
-
Philip Weaver
-
Tillmann Rendel
-
Tom Phoenix