Hi Nickolay,

Yes, that was my first idea too, but String is more often used in reporting errors in Either's Left, so just an example.

> ... or can unambiguously determine the cause ...
Not always when Maybe is used.


> ... is more readable ...
The words Maybe (..) are fine, but the reason I asked is that it seems to me that we have two distinct elements for the same thing, instead of two distinct synonyms for the same thing.


vlatko

-------- Original Message --------
Subject: Re: [Haskell-cafe] Why Maybe exists if there is Either?
From: Nickolay Kudasov <nickolay.kudasov@gmail.com>
To: vlatko.basic@gmail.com
Cc: "haskell-cafe@haskell.org" <haskell-cafe@haskell.org>
Date: 09.01.2014 16:14


Hi Vlatko,

Actually, Maybe can be seen as Either () a. Not String or Int because then you would have multiple Nothings (if Left "" is Nothing then what would Left "hello" be?). So Either e a is (generally) somewhat bigger than Maybe a.

Since Either can be used to represent strictly bigger types, you may not want it sometimes. lookup function (to find element in a list by its index) is an example. It is unnecessary to keep extra information in () or String or Int about what caused failure. So if we either don’t care what caused failure or can unambiguously determine the cause Maybe suits better (is more readable) than Either ().

Nick



2014/1/9 Vlatko Basic <vlatko.basic@gmail.com>
Hello Cafe,

With my current knowledge of Haskell, I do not see why is there Maybe if we have Either.

For example, Functor and Monad instances (and many others) of Maybe and Either are the same (except for fail).

In other words, this should hold:

    Maybe a  = Either String a     -- String or something else
    Nothing   = Left ""
    Just a       = Right a


I'm curious to find out what was the reasoning to make Maybe?
What is the added value with introducing it?
In which situations the above substitution does not hold?



Best regards,

vlatko

_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe