[erlang-questions] conditional expressions

damien morton <>
Sat Nov 15 16:09:43 CET 2008


On Sun, Nov 16, 2008 at 1:48 AM, Richard Carlsson <> wrote:

> damien morton wrote:
>
>>
>>  Still, what strikes me about the erlang libraries is the tremendous
>> variety of techniques used to signal the return of a value or not.
>>
>> Sometimes nil/Value, sometimes false/Value, sometimes []/[Value],
>> sometimes false/{value,Value}
>>
>
>
> I've tried to promote {value,X}/none as a standard maybe-type, but it's
> hard to do much about all the existing code out there.
>
>  For a function that can return 0 or 1 answers, I personally like the
>> []/[Value] approach.
>>
>
> []/[X] is ok for "searches" as in mnesia, where in some cases you can
> get several elements as a result, but as a general mechanism it always
> makes a reader think "so, can I ever get more than one value here?", so
> it's not good for clarity.
>

Would {}/{X} be more clear for 0 or 1 answers, and []/[...] for 0 or more
answers?

Not too keen on the none/{value,Value} approach - it feels irregular
somehow.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20081116/d4c653e9/attachment.html>


More information about the erlang-questions mailing list