[Haskell-cafe] Why Maybe exists if there is Either?
Dan Frumin
difrumin at gmail.com
Fri Jan 10 09:55:35 UTC 2014
> On 10 Jan 2014, at 04:17, John Lato <jwlato at gmail.com> wrote:
>
>> 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.
>
Why is 'Either Void a' isomorphic to 'Maybe a'. What would 'Nothing' be in this case?
Either () a is the correct version. Roughly speaking 'Maybe a' contains |a|+1 values while Either Void a contains only |a| values, since you can not construct any Left's
> John L.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140110/5c8ecec2/attachment-0001.html>
More information about the Haskell-Cafe
mailing list