Enhanced type guard syntax]

Valentin valentin@REDACTED
Thu Sep 18 20:45:29 CEST 2003


Sometimes it might be useful to be able to write:

isOne( X )    when X == 1; X == "one"    ->    true;
isOne( X )    ->  false.

Why would I ever want to (re)write it like this:

isOne( X/integer )    -> 
    case X of
        1 ->    true;
        _ ->    false
    end;

isOne( X/string ) ->
    case X of
        "one"    ->    true;
        _        ->    false
    end.

Most of the languages are either STRONGLY or weakly typed.
Erlang can be both and more -- it can match patterns that can 
be specified/grouped through their semantics, not only syntax.
For example, when we say ONE, we can write it as "1" or
"one" -- it wouldn't change the meaning, right? 


Valentin.




More information about the erlang-questions mailing list