Higher Order Function Question

Fredrik Linder <>
Fri May 24 18:06:33 CEST 2002

> As for
> 4> apply({attr, isPk}, [A1]).
> as I mentioned, I was just testing for eventual use in filter, and as far
> I know, in filter (and map, etc.) you *must* use the form {attr, isPk}. I
> always get errors when I try attr:isPk within map, filter etc.

You *must* supply a fun, but there are three alternatives to define one, the
one you chose I guess is considered to be the least elegant.

Fun = {M, F}
Fun = fun M:F/A, where A = arity (requires that M:F/A is a named existing
Fun = fun(Arg) -> M:F(Arg) end

The apply call above can even be written:

{attr, isPk}(A1)     %% !!!
fun(X) -> attr:isPk(X) end(A1)

or simply

attr:isPk(A1)  ;-)


More information about the erlang-questions mailing list