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

Johannes Erber Hannes_E at gmx.de
Thu Jan 9 16:00:01 UTC 2014


Hi Vlatko,

it is not only about convenience, but also about readability and 
conciseness which are quite important in order to maintain software and 
to prevent it from getting cluttered up unnecessarily.

Also Maybe evolves naturally as minimal complete type for use cases in 
which you can have either a value or no value. Either extends Maybe by 
more information why no value is returned by a function. Of course you 
could replace Maybe with Eithers and your code would still work, but it 
would be much less concise and hence maintainable.

Best,
Johannes

On 09/01/2014 15:26, Vlatko Basic wrote:
> Hi Johannes,
>
> I thought there was some "more important" reason than convenience, so 
> I asked. :-O)
>
> I put String because I'm currently thinking about error handling, and 
> Left String is the usual way of reporting failure, and I see Maybe as 
> a type for reporting errors, failures and similar.
>
>
> Somehow it looks to me that famous "8 ways to report errors in 
> Haskell" could be shortened by one if Maybe is replaced with Either 
> (with appropriate synonyms, of course).
>
>
> vlatko
>
> -------- Original Message  --------
> Subject: Re: [Haskell-cafe] Why Maybe exists if there is Either?
> From: Johannes Erber <Hannes_E at gmx.de>
> To: vlatko.basic at gmail.com, haskell-cafe at haskell.org 
> <haskell-cafe at haskell.org>
> Date: 09.01.2014 16:07
>
>> Hi Vlatko,
>>
>> to keep programs clear, short and simple. What makes you choose 
>> String as type
>> to replace Nothing?
>>
>> Best,
>> Johannes
>>
>> On 09/01/2014 14:50, Vlatko Basic wrote:
>>> 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 at haskell.org
>>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>>



More information about the Haskell-Cafe mailing list