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

Ben Gamari bgamari.foss at gmail.com
Thu Jan 9 19:29:04 UTC 2014


Brandon Allbery <allbery.b at gmail.com> writes:

> On Thu, Jan 9, 2014 at 12:11 PM, Ben Foppa <benjamin.foppa at gmail.com> wrote:
>
>> 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
>>
> Not until you try to pattern match on it....
>
Although with pattern synonyms[1][2] this will become possible if I'm
not mistaken,

    pattern Nothing = Left ()
    pattern Just a = Right a

Cheers,

- Ben


[1] https://ghc.haskell.org/trac/ghc/ticket/5144
[2] https://ghc.haskell.org/trac/ghc/wiki/PatternSynonyms 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 489 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140109/422b164c/attachment.sig>


More information about the Haskell-Cafe mailing list