Proposed change to libraries

Kostis Sagonas kostis@REDACTED
Wed Feb 9 22:56:11 CET 2005


Carsten Schultz wrote:
 > On Wed, Feb 09, 2005 at 12:09:49PM +0100, Kostis Sagonas wrote:
 > >
 > >     map({M,F}, L) -> map(fun(X) -> M:F(X) end, L);
 > >     map(F, [H|T]) -> [F(H) | map(F, T)];
 > >     map(F, []) when is_function(F,1) -> [].
 > >
 > 
 > How clever is the compiler?  Will it be necessary to write
 > 
 > map({M,F}, L) -> map_(fun(X) -> M:F(X) end, L);
 > map(F, L) when is_function(F, 1) -> map_(F, L).
 > 
 > map_(F, [H|T]) -> [F(H) | map_(F, T)];
 > map_(F, []) -> [].
 > 
 > (possibly with additional guards in map_/2, if that makes the
 > compiler/an analyzer happier) to avoid a performance penalty?

Ever since I wrote my mail, I've been wondering whether someone
would notice this -- very good that someone actually did!

Indeed, to be sure, one has to write the program as written by
Carsten above (currently, the Erlang compiler is not so clever
to do it automatically, but we might work on this ;-)  So this
is how the library has to be modified.

However, the good news is that the new type analysis that we
are currently implementing does not need any extra guards in
map_/2 to infer proper types.

Kostis.




More information about the erlang-questions mailing list