[Haskell-cafe] Why Maybe exists if there is Either?

John Lato jwlato at gmail.com
Fri Jan 10 00:17:54 UTC 2014


On Thu, Jan 9, 2014 at 8:51 AM, Artyom Kazak <yom at artyom.me> wrote:

>
> On 01/09/2014 08:36 PM, Vlatko Basic wrote:
>
>> But instance declarations wouldn't be needed because we already have all
>> the instances for Either. The point would be to have them unified.
>>
> Consider a generic Show instance for Either – there’s no way¹ to make it
> behave differently for Either () (or Maybe if it was a type synonym). I
> think there are other cases in which we want Maybe to behave differently
> from Either, but I can’t think of any on the spot.
>
> ¹ this point also applies to String, which is a type synonym for [Char] –
> and it was solved somewhat inelegantly by adding an additional method to
> Show typeclass *specifically* for showing lists of things.


I think this is a really important point.  If I may go further, it's
arguable that 'type String = [Char]' was a poor decision, and one of the
arguments is that it's not possible to make different instances for String
and [a] (hence the showsList issue).

Also, due to laziness, Either () a is bigger than Maybe a.  It should be
'Either Void a'.   But Void has only recently been added to the
standard-ish library, which means if we'd used Either () from the start now
we'd be stuck with the wrong type.  I'd rather have a separate Maybe that
does exactly what it's meant to.

John L.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140109/876ab985/attachment.html>


More information about the Haskell-Cafe mailing list