Proposed change to libraries
Richard A. O'Keefe
ok@REDACTED
Tue Feb 8 01:51:20 CET 2005
The bad news is that F must be allowed to be a "tuple fun" too,
to keep backward compatibility.
Thus the revised code must look like this:
map(F, [H|T]) ->
[F(H)|map(F, T)];
map(F, []) when is_function(F) -> %% andalso is_fun_arity(F) == 1
[];
map({M,F}, []) when is_atom(M), is_atom(F) ->
[].
That should still give the Dialyzer more information about the type.
Everywhere we have an argument that should be a function but might not
always be applied we are going to have the same problem. A fix that adds
an extra clause is going to be a pain.
We need
is_applicable(F, N)
- succeeds or returns true when N is a non-negative integer
and F is such that F(T1,...,TN) would make sense
- fails or returns false otherwise
is_applicable(F)
- succeeds or returns true when there exists an N such that
is_applicable(F, N) would succeed or return true
- fails or returns false otherwise
Then
map(F, [F|T]) -> [F(H)|map(F,T)];
map(F, []) when is_applicable(F, 2) -> [].
More information about the erlang-questions
mailing list