[Haskell-cafe] Why Maybe exists if there is Either?
Daniil Frumin
difrumin at gmail.com
Thu Jan 9 16:42:57 UTC 2014
But you actually might want different instances for `Maybe` and for `Either`.
For example, let's say that you have a typeclasse for serializing
data-structures into a database.
In case of Maybe you want to serialize `Nothing` into 'NULL' or
something similar; in case of Either you want to have an
entirely different structure.
Additionally, as it have been mentioned, `Either String a` is not the
same thing as `Maybe a`.
Say, you have a value of type `Either String a`. How do you know that
all `Left`-values are suppose to be empty string?
What do you actually want is `Either () a`.
On Thu, Jan 9, 2014 at 8:36 PM, Vlatko Basic <vlatko.basic at gmail.com> wrote:
> Hi Artyom,
>
> Yes, indeed.
>
> But instance declarations wouldn't be needed because we already have all the
> instances for Either. The point would be to have them unified.
> But it is a problem that there are no data constructor synonyms in Haskell.
> So at least pattern matching wouldn't be possible the simple way. Maybe
> ViewPatterns could (partially) solve that.
>
>
>
> vlatko
>
> -------- Original Message --------
> Subject: Re: [Haskell-cafe] Why Maybe exists if there is Either?
> From: Artyom Kazak <yom at artyom.me>
> To: haskell-cafe at haskell.org
> Date: 09.01.2014 16:23
>
>> Besides, even defining
>>
>> type Maybe a = Either () a
>>
>> in standard library wouldn’t be the same as
>>
>> data Maybe a = Nothing | Just a
>>
>> since in Haskell 98 type synonyms aren’t allowed in instance declarations,
>> which
>> means that programmers would still have to remember that `Maybe` is
>> actually
>> `Either ()` under-the-hood every time when writing an instance.
>> _______________________________________________
>> 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
--
Sincerely yours,
-- Daniil
More information about the Haskell-Cafe
mailing list