[Haskell-cafe] Why does Haskell have both `Maybe a` and `Either a ()`?

Henning Thielemann lemming at henning-thielemann.de
Fri May 29 10:38:49 UTC 2020

On Fri, 29 May 2020, Wiebe-Marten Wijnja wrote:

> Greetings, everyone!
> Recently I was involved in a discussion on the new ML-style language
> 'gleam'.
> Gleam has for quite a while now only had an `Either a b` type,
> with all functions that in Haskell one would use a `Maybe a` for,
> working on an `Either a ()` instead.

In Haskell `Maybe a` is more similar to `Either () a` than `Either a ()`.

Either has one more redirection on the Left case. You can have both `Left 
undefined` and `Left ()` whereas Maybe can only have `Nothing`. I hardly 
think that people actually make use of this difference, though.

Btw. from a software engineering point I'd prefer not to use Either for 
both exception handling with an according Monad and for cases where you 
just want to handle values of two possible types. I'd define an Except 
type for the exception usage.

Could we remove Maybe in favor of Either? It would make some instances 
non-Haskell-98. E.g.

   instance C Maybe where

is Haskell 98, but

   instance C (Either ()) where

needs FlexibleInstances and

   instance (a ~ ()) => C (Either a) where

needs TypeFamilies.

Unless you find out that you can define a more general instance like

   instance (Super a) => C (Either a) where


More information about the Haskell-Cafe mailing list