Enhanced type guard syntax]

Vlad Dumitrescu vlad_dumitrescu@REDACTED
Fri Sep 19 10:53:07 CEST 2003


While I'm no guru, I'll give my 2c

From: "Peter-Henry Mander"
> If you _need_ to know what type of parameter is being given as an
> argument, would it be more explicit and practical to simply use tagged
> tuples?
>
>  > is  f(X) when list(integer(X)) ->
>  > a good notation to express that X should be a list of integers?
>
> perhaps this:
>
>      f({list_of_integers,X}) ->
>
> will provide a strong enough guard to to prevent illegal use of this
> function.

The idea is certainly interesting, but one problem that I can see is that one
has to either

- return {list_of_integers, Value} from all functions that compute such a beast

or

- be forced to write
        Result = fun_that_returns_a_list_of_integers(),
        f({list_of_integers, Result}),
  instead of
        f(fun_that_returns_a_list_of_integers()),

The big advantage of using the real types and not tags is that they are present
in the runtime, while invisible in the code.

regards,
Vlad



More information about the erlang-questions mailing list