"Elvis" operator (?:) as a reverse infix form of "fromMaybe"

Edward Kmett ekmett at gmail.com
Sun Oct 13 04:30:16 UTC 2013


I'm pretty strongly -1 on this proposal.

Operator names are fairly precious, and nothing about this operator name
really screams "Maybe".

Seen in code without prior knowledge `fromMaybe` can have its meaning
intuited. (?:) on the other hand comes across as gratuitous.

-Edward


On Sat, Oct 12, 2013 at 8:40 AM, Nikita Volkov <nikita.y.volkov at gmail.com>wrote:

> I suggest to include this operator in "Data.Maybe" and "Prelude".
>
> *Implementation:*
>
>     (?:) :: Maybe a -> a -> a
>     maybeA ?: b = fromMaybe b maybeA
>
> *Use cases:*
>
>     1.
>         maybeValue ?: error "Value is unexpectedly empty. This is a bug."
>
>     instead of
>
>         fromMaybe (error "Value is unexpectedly empty. This is a bug.")
> maybeValue
>
>     2.
>         maybeA ?: maybeB ?: c
>
>     instead of
>
>         fromMaybe (fromMaybe c maybeB) maybeA
>
> *Name collisions:*
>
>     Hayoo search gives only 6 collisions with 5 hardly fundamental
> libraries.
>
>
>
> * The nickname and the operator itself are inspired by the ones from
> Groovy language.
>
> ** The symbols of the operator are a reminder of plain old ternary
> construct.
>
> *** To understand the nickname look at the operator as on emoticon.
>
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/libraries/attachments/20131013/86867a32/attachment.html>


More information about the Libraries mailing list