[erlang-questions] Question about higher order function
Jan Henry Nystrom
jan@REDACTED
Fri Nov 30 19:02:53 CET 2007
Hi,
If you write
-module(HOF).
-export([first/1]).
fst({A,B}) -> A.
first(L) -> lists:map(fun fst/1, L).
It is less awkward.
/Cheers Henry
Burkhard Neppert wrote:
> Hello,
>
> I try to use higher order functions but cannot pass functions as
> argument unless
> I wrap them in an anonymous function.
> Can someone tell me if I'm doing something wrong here or if Erlang is
> really so
> akward and clumsy why it is this way?
>
> Regards
>
> Burkard Neppert
>
> -module(HOF).
> -export([first/1]).
> fst({A,B}) -> A.
> % This does not compile
> % first(L) ->
> % lists:map(fst, L).
> % but this does:
> first(L) ->
> lists:map(fun (E) -> fst(E) end, L). % but this is terrible
>
> %%%%%
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
--
Jan Henry Nystrom <jan@REDACTED>
Training & Research Manager @ Erlang Training and Consulting Ltd
http://www.erlang-consulting.com
More information about the erlang-questions
mailing list