
Hi All, I've been [trying to] grapple with the various monads and transformers, and it occurs to me that the standard instance for Either as a monadic type is unnecessarily restrictive. Is there a compelling reason that it is not just instance Monad (Either e) where return = Right (Left e) >>= f = Left e (Right x) >>= f = f x abort = Left Tom

On Tue, Oct 03, 2006 at 10:44:49AM +1000, Thomas Conway wrote:
I've been [trying to] grapple with the various monads and transformers, and it occurs to me that the standard instance for Either as a monadic type is unnecessarily restrictive. Is there a compelling reason that it is not just
instance Monad (Either e) where return = Right (Left e) >>= f = Left e (Right x) >>= f = f x
abort = Left
That is the definition one would expect, but the restriction was added so that the instance could include a definition of fail. It's evidence that including fail in Monad is a wart, IMO. Using strings to represent errors has severe limitations.

On Oct 3, 2006, at 03:49 , Ross Paterson wrote:
On Tue, Oct 03, 2006 at 10:44:49AM +1000, Thomas Conway wrote:
I've been [trying to] grapple with the various monads and transformers, and it occurs to me that the standard instance for Either as a monadic type is unnecessarily restrictive. Is there a compelling reason that it is not just
instance Monad (Either e) where return = Right (Left e) >>= f = Left e (Right x) >>= f = f x
abort = Left
That is the definition one would expect, but the restriction was added so that the instance could include a definition of fail. It's evidence that including fail in Monad is a wart, IMO. Using strings to represent errors has severe limitations.
Yes, having fail in the Monad is a horrible wart. And like some other warts in Haskell it was added to cure the symptom rather than the disease. :( -- Lennart

On Tue, Oct 03, 2006 at 07:52:54AM -0400, Lennart Augustsson wrote:
Yes, having fail in the Monad is a horrible wart. And like some other warts in Haskell it was added to cure the symptom rather than the disease. :(
Switching metaphors, what do you see as the disease in this case? (As far as I know, it's there for the translation of pattern match failure in do-expressions.)

Ross Paterson wrote:
On Tue, Oct 03, 2006 at 07:52:54AM -0400, Lennart Augustsson wrote:
Yes, having fail in the Monad is a horrible wart.
(As far as I know, it's there for the translation of pattern match failure in do-expressions.)
I think it would be much less of a wart if the signature for fail was just: fail :: m a because what's the point of the String argument anyway (other than trying to hack a kind of half-baked debug facility into the language)? Regards, Brian. -- Logic empowers us and Love gives us purpose. Yet still phantoms restless for eras long past, congealed in the present in unthought forms, strive mightily unseen to destroy us. http://www.metamilk.com

It all came about because pattern matching failure sometimes cause a do expression to be in MonadZero rather than Monad with the old translation. This gave rise to confusing error messages, it was claimed. This was the disease. -- Lennart On Oct 3, 2006, at 08:28 , Ross Paterson wrote:
On Tue, Oct 03, 2006 at 07:52:54AM -0400, Lennart Augustsson wrote:
Yes, having fail in the Monad is a horrible wart. And like some other warts in Haskell it was added to cure the symptom rather than the disease. :(
Switching metaphors, what do you see as the disease in this case? (As far as I know, it's there for the translation of pattern match failure in do-expressions.)
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (4)
-
Brian Hulley
-
Lennart Augustsson
-
Ross Paterson
-
Thomas Conway