[erlang-questions] Maps branch and disclaimers

Siraaj Khandkar <>
Tue Oct 29 21:15:15 CET 2013


On 10/29/2013 03:51 PM, Chris King wrote:
>
> On Tue, Oct 29, 2013 at 3:41 PM, Jesper Louis Andersen
> <
> <mailto:>> wrote:
>
>
>     view(eq) -> 0;
>     view(lt) -> -1;
>     view(gt) -> 1.
>
>     This function is exhaustive in the input type.
>
>
> No it's not.  Unless you define the input type as :- type order() :: eq
> | lt | gt.  Well, you can do the same thing with integers in Erlang: :-
> type order() :: -1 | 0 | 1.

Sure. Let's entertain this thought for a sec: the lt|eq|gt are in the 
domain of atoms and are impractical to make _truly_ exhaustive. However, 
remember this - atoms, by their very purpose, carry symbolic meaning, 
whereas integers do not. If you see 0 or 1 or -1 outside of context - 
they mean next to 0 to you (pun very much intended), whereas if you see 
'lt', 'gt' or 'eq' - you have a pretty good clue about where they could 
have come from.


>
>     Another problem with an integer is that
>
>     compare(X, Y) * compare(Y, Z) is a valid expression, but it has no
>     meaning whatsoever.
>
>
> And with atoms, list_to_atom(lists:append(atom_to_list(X),
> atom_to_list(Y)) is equally meaningless.
>
>



More information about the erlang-questions mailing list