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

Dan Burton danburton.email at gmail.com
Sat Oct 12 19:46:06 UTC 2013


It's not a completely different thing, it's the very same thing, but more
general.

-- Dan Burton


On Sat, Oct 12, 2013 at 12:41 PM, Nikita Volkov
<nikita.y.volkov at gmail.com>wrote:

> John Lato, you're offering a completely different thing and I would
> totally vote against it. Please don't flood.
>
>
> 2013/10/12 John Lato <jwlato at gmail.com>
>
>> I'd prefer it if we had an operator in Control.Applicative such as
>>
>>   |> :: Alternative f => f a -> a -> f a
>>   l |> r = l <|> pure r
>>
>> if it doesn't already exist, this would generalize fromMaybe, and
>> complicated cases could be written as
>>
>>   maybeA <|> maybeB |> c
>>
>> but even this could be easily written using <|> and pure, so I'm not sure
>> it pulls its weight.
>>
>> John L.
>>
>>
>> On Sat, Oct 12, 2013 at 7: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
>>>
>>>
>>
>
> _______________________________________________
> 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/20131012/c75a9aab/attachment.html>


More information about the Libraries mailing list