#4159: move Monad and MonadFix instances for Either from mtl
ml at isaac.cedarswampstudios.org
Fri Jul 2 12:25:33 EDT 2010
On 07/02/10 08:13, John Lato wrote:
>> From: Ross Paterson<ross at soi.city.ac.uk>
>> 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.
More information about the Libraries