Re: #4159: move Monad and MonadFix instances for Either from mtl to base

From: Ross Paterson
On Thu, Jul 01, 2010 at 11:35:24AM +0100, Simon Marlow wrote:
I don't know all the ins and outs of the discussion here, but before proposing to reverse this decision someone should do a careful assessment of the prior rationale and results of subsequent experience.
The general question of fail is a side issue -- the question here is just whether the Monad instance for Either should define fail, and if so to what.
I think it should not define fail (or define it to error). I've never been happy with the semantics of this instance. I thought the point of Either was that neither value had any special meaning attached to it, and in particular that "Left" and "Right" were chosen as being free of any connotations of correct, incorrect, or other. Defining fail as "Left x" seems wrong because it codifies the left value as an error. In my opinion those semantics belong to another type. John

On 07/02/10 08:13, John Lato wrote:
From: Ross Paterson
The general question of fail is a side issue -- the question here is just whether the Monad instance for Either should define fail, and if so to what. I think it should not define fail (or define it to error). I've never been happy with the semantics of this instance. I thought the point of Either was that neither value had any special meaning attached to it, and in particular that "Left" and "Right" were chosen as being free of any connotations of correct, incorrect, or other. Defining fail as "Left x" seems wrong because it codifies the left value as an error. In my opinion those semantics belong to another type.
It's not quite as simple as that -- as soon as we start making Either an instance of kind (* -> *) classes, such as Functor and Monad, there inevitably becomes some kind of semantic difference between Left and Right. Still, I support Ross's proposal of fail=error . Either's 'fail' could just as type-correctly be defined 'fail s = Right (error s)', even though no one would be happy about that... which makes me suspicious of defining it as 'fail s = Left (error s)' too. -Isaac

Excerpts from Isaac Dupree's message of Fri Jul 02 12:25:33 -0400 2010:
It's not quite as simple as that -- as soon as we start making Either an instance of kind (* -> *) classes, such as Functor and Monad, there inevitably becomes some kind of semantic difference between Left and Right.
Right, so what we end up with is short-circuiting computation with different results. Cheers, Edward

I am against adding the instances for Monad Either to the base package
for the same reasons as the ones in the thread "proposal #4095: add
Applicative instance for Either".
http://www.haskell.org/pipermail/libraries/2010-June/013715.html
-Iavor
On Wed, Jul 7, 2010 at 6:06 PM, Edward Z. Yang
Excerpts from Isaac Dupree's message of Fri Jul 02 12:25:33 -0400 2010:
It's not quite as simple as that -- as soon as we start making Either an instance of kind (* -> *) classes, such as Functor and Monad, there inevitably becomes some kind of semantic difference between Left and Right.
Right, so what we end up with is short-circuiting computation with different results.
Cheers, Edward _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

On Fri, Jul 16, 2010 at 12:58:39AM -0700, Iavor Diatchki wrote:
I am against adding the instances for Monad Either to the base package for the same reasons as the ones in the thread "proposal #4095: add Applicative instance for Either". http://www.haskell.org/pipermail/libraries/2010-June/013715.html
namely:
The benefit of omitting some instances is that when programmers find them lacking, they might consider an alternative way to achieve their goal. In the case of Monad and Either, my feeling is that an alternative would almost always lead to code which is easier to understand.
I don't believe that witholding valid canonical instances to force a different style is viable in general. In this particular case there is already an instance in mtl, and (+ e) is used as an example is just about every paper on monads.

Hello,
I don't mind the instance being in MTL because then I can choose if I
should use it or not.
Adding it to the base library will force it on everyone.
I agree that this is a matter of taste but I also think that being
careful about what to _omit_ is an important part of good design.
So far, I have not seen any convincing reasons about why we might need
this instance.
-Iavor
PS: About (+ e) being used in papers on monads: the instance we are
adding is actually "Either e" which would be confusing enough for
someone who is just learning about these things. It would be even
more confusing when---having finally figured out the
correspondence---they tried to define the instance from the paper and
got an "overlapping instance" error.
PPS: I don't mean to sound too negative here (I am told I have some
skill for it though :-). Examples of the utility of this instance
would be most welcome though.
On Wed, Jul 21, 2010 at 7:54 AM, Ross Paterson
On Fri, Jul 16, 2010 at 12:58:39AM -0700, Iavor Diatchki wrote:
I am against adding the instances for Monad Either to the base package for the same reasons as the ones in the thread "proposal #4095: add Applicative instance for Either". http://www.haskell.org/pipermail/libraries/2010-June/013715.html
namely:
The benefit of omitting some instances is that when programmers find them lacking, they might consider an alternative way to achieve their goal. In the case of Monad and Either, my feeling is that an alternative would almost always lead to code which is easier to understand.
I don't believe that witholding valid canonical instances to force a different style is viable in general. In this particular case there is already an instance in mtl, and (+ e) is used as an example is just about every paper on monads. _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries

Iavor Diatchki schrieb:
Hello, I don't mind the instance being in MTL because then I can choose if I should use it or not.
You cannot really choose - if only one imported package transitively depends on MTL you get that instance. Dependencies on Hackage are so big today, that it is very likely to get MTL or transformers imported that way.

On Wed, Jul 21, 2010 at 11:05:02AM -0700, Iavor Diatchki wrote:
PS: About (+ e) being used in papers on monads: the instance we are adding is actually "Either e" which would be confusing enough for someone who is just learning about these things. It would be even more confusing when---having finally figured out the correspondence---they tried to define the instance from the paper and got an "overlapping instance" error.
Yes, Either is the Prelude version of +. As for the overlap, the same thing will happen if they read in those papers about (->) r and try to declare that -- it's already there.
PPS: I don't mean to sound too negative here (I am told I have some skill for it though :-). Examples of the utility of this instance would be most welcome though.
Those papers have a few.

I find the Either monad is a nice cheap upgrade from the Maybe monad. If I read your objections correctly you would prefer that I define a custom datatype that explicit enumerates the possible errors. That would be rather too heavyweight for casual use, in my opinion. Iavor Diatchki wrote:
Hello, I don't mind the instance being in MTL because then I can choose if I should use it or not. Adding it to the base library will force it on everyone. I agree that this is a matter of taste but I also think that being careful about what to _omit_ is an important part of good design. So far, I have not seen any convincing reasons about why we might need this instance. -Iavor
PS: About (+ e) being used in papers on monads: the instance we are adding is actually "Either e" which would be confusing enough for someone who is just learning about these things. It would be even more confusing when---having finally figured out the correspondence---they tried to define the instance from the paper and got an "overlapping instance" error.
PPS: I don't mean to sound too negative here (I am told I have some skill for it though :-). Examples of the utility of this instance would be most welcome though.
On Wed, Jul 21, 2010 at 7:54 AM, Ross Paterson
wrote: On Fri, Jul 16, 2010 at 12:58:39AM -0700, Iavor Diatchki wrote:
I am against adding the instances for Monad Either to the base package for the same reasons as the ones in the thread "proposal #4095: add Applicative instance for Either". http://www.haskell.org/pipermail/libraries/2010-June/013715.html
namely:
The benefit of omitting some instances is that when programmers find them lacking, they might consider an alternative way to achieve their goal. In the case of Monad and Either, my feeling is that an alternative would almost always lead to code which is easier to understand.
I don't believe that witholding valid canonical instances to force a different style is viable in general. In this particular case there is already an instance in mtl, and (+ e) is used as an example is just about every paper on monads. _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
=============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ===============================================================================

Hi,
Not really, enumerating errors is a good idea in some cases but, as
you point out, it is too much work in others. I think that we should
simply have another type, isomorphic to Either, but with more
suggestive names for the type and its constructors for error handling.
Picking appropriate names for things makes a surprisingly big
difference when reading large amounts of code, especially when you are
not the program's author. In general, I think that a good principle
is to aim for designing programs which are "self documenting" in the
sense that you could understand an algorithm without having to
know/remember implicit conventions such as "errors are usually on the
left".
Either way :) this is not a huge deal, so if other people find these
instances so useful, I should not stop the process. I would be a lot
more opposed to "standard" library functions getting Either types for
error reporting though.
-Iavor
On Wed, Jul 21, 2010 at 1:38 PM, Sittampalam, Ganesh
I find the Either monad is a nice cheap upgrade from the Maybe monad. If I read your objections correctly you would prefer that I define a custom datatype that explicit enumerates the possible errors. That would be rather too heavyweight for casual use, in my opinion.
Iavor Diatchki wrote:
Hello, I don't mind the instance being in MTL because then I can choose if I should use it or not. Adding it to the base library will force it on everyone. I agree that this is a matter of taste but I also think that being careful about what to _omit_ is an important part of good design. So far, I have not seen any convincing reasons about why we might need this instance. -Iavor
PS: About (+ e) being used in papers on monads: the instance we are adding is actually "Either e" which would be confusing enough for someone who is just learning about these things. It would be even more confusing when---having finally figured out the correspondence---they tried to define the instance from the paper and got an "overlapping instance" error.
PPS: I don't mean to sound too negative here (I am told I have some skill for it though :-). Examples of the utility of this instance would be most welcome though.
On Wed, Jul 21, 2010 at 7:54 AM, Ross Paterson
wrote: On Fri, Jul 16, 2010 at 12:58:39AM -0700, Iavor Diatchki wrote:
I am against adding the instances for Monad Either to the base package for the same reasons as the ones in the thread "proposal #4095: add Applicative instance for Either". http://www.haskell.org/pipermail/libraries/2010-June/013715.html
namely:
The benefit of omitting some instances is that when programmers find them lacking, they might consider an alternative way to achieve their goal. In the case of Monad and Either, my feeling is that an alternative would almost always lead to code which is easier to understand.
I don't believe that witholding valid canonical instances to force a different style is viable in general. In this particular case there is already an instance in mtl, and (+ e) is used as an example is just about every paper on monads. _______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
_______________________________________________ Libraries mailing list Libraries@haskell.org http://www.haskell.org/mailman/listinfo/libraries
=============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ===============================================================================

On Wed, Jul 21, 2010 at 04:46:09PM -0700, Iavor Diatchki wrote:
Picking appropriate names for things makes a surprisingly big difference when reading large amounts of code, especially when you are not the program's author.
That's a useful principle, but few follow it all the way to its logical conclusion. It's also useful to have a few standard types, to provide a common interface between user functions and lots of utility functions. That's why we have lists and pairs, and Maybe and Either.

Ross Paterson schrieb:
is already an instance in mtl, and (+ e) is used as an example is just about every paper on monads.
Can you give a reference for "(+ e)"? Is this the (infix) union type constructor (to be written as :+)? If it corresponds to "Either e" should it not be written as "(+) e", because "(+ e)" interpreted like a haskell section would address the second type argument (which is not possible to address in instances)? data a :+ b = Left a | Right b instance Monad ((:+) e) Cheers Christian P.S. "instance Monad (:+ e)" gives a parse error

On Thu, Jul 22, 2010 at 01:16:20PM +0200, Christian Maeder wrote:
Ross Paterson schrieb:
is already an instance in mtl, and (+ e) is used as an example is just about every paper on monads.
Can you give a reference for "(+ e)"? Is this the (infix) union type constructor (to be written as :+)? If it corresponds to "Either e" should it not be written as "(+) e", because "(+ e)" interpreted like a haskell section would address the second type argument (which is not possible to address in instances)?
True, most papers use M a = a + E, but we have to flip the arguments to write an instance in Haskell.
participants (8)
-
Christian Maeder
-
Edward Z. Yang
-
Henning Thielemann
-
Iavor Diatchki
-
Isaac Dupree
-
John Lato
-
Ross Paterson
-
Sittampalam, Ganesh