Proposed change to libraries
Bjorn Gustavsson
bjorn@REDACTED
Mon Feb 7 12:07:26 CET 2005
Kostis Sagonas <kostis@REDACTED> writes:
[...]
>
> I.e., change the implementation of map/2 (and similar functions)
> as if defined by:
>
> map(F, [H|T]) ->
> [F(H)|map(F, T)];
> map(F, []) when is_function(F) -> %% andalso is_fun_arity(F) == 1
> [].
I have some good news and some bad news. :-)
The good news is that we can change lists:map/2 and friends in
R10B-4 to reject an F that is not a fun. That is merely a bug fix
and does not break backward compatibility.
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.
/Björn
--
Björn Gustavsson, Erlang/OTP, Ericsson AB
More information about the erlang-questions
mailing list