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

Ben Foppa benjamin.foppa at gmail.com
Thu Jan 9 17:11:49 UTC 2014


I'm generally of the opinion that if things can be unified under the hood,
it makes for fewer edge cases and easier testing.

It also seems to me that I describe Maybe and Either () in the same way, if
I were to explain verbally: "it's either nothing, or it's something".

Aside from the point made about typeclass instances, I don't see an issue
with:

type Maybe = Either ()

nothing :: Maybe a
nothing = Left ()

just :: a -> Maybe a
just = Right
On Jan 9, 2014 12:02 PM, "Niklas Larsson" <metaniklas at gmail.com> wrote:

>  Maybe doesn't have to be used for error reporting. Optional values is a
> very big use case for it.
>  ------------------------------
> Från: Vlatko Basic <vlatko.basic at gmail.com>
> Skickat: 2014-01-09 16:37
> Till: haskell-cafe at haskell.org
> Ämne: Re: [Haskell-cafe] Why Maybe exists if there is Either?
>
> Hi Daniel,
>
> > If you just want to signalize a fail case without any additional
> > information, then a Maybe fits better than an Either, because
> > why should you need this bogus empty string?
>
> Now it looks to me that it might be better and more consistent to write an
> empty
> bogus string (as with: nothing = Left "") than to have two distinct ways
> of
> error reporting, and both are used widely and often should be intermixed.
> And at the end, call site could decide does it want to use the string or
> not.
>
>
> vlatko
>
>
> -------- Original Message  --------
> Subject: Re: [Haskell-cafe] Why Maybe exists if there is Either?
> From: Daniel Trstenjak <daniel.trstenjak at gmail.com>
> To: haskell-cafe at haskell.org
> Date: 09.01.2014 16:13
>
> >
> > Hi Vlatko,
> >
> > On Thu, Jan 09, 2014 at 03:50:16PM +0100, Vlatko Basic wrote:
> >> 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?
> >
> > If you just want to signalize a fail case without any additional
> > information, then a Maybe fits better than an Either, because
> > why should you need this bogus empty string?
> >
> > How should you know that the string doesn't contain something relevant?
> >
> >
> > Greetings,
> > Daniel
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> _______________________________________________
> 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/20140109/6e8d0748/attachment.html>


More information about the Haskell-Cafe mailing list