I am playing around with example code from Programming with Erlang. I am struck with funs. help me understand whats going wrong with below code.
-export([totalcost/1]).
Costeach = fun(X) -> {W,Q} = X, shop:cost(W)*Q end.
sum(H|T) -> H + sum[T];
sum([]) -> 0.
totalcost(L) -> sum(lists:map(Costeach,L)).
All i wanted to achieve was being able to pass Variable (with fun assigned to it) as parameter to map. get total cost from this module
i keep getting syntax error/ Costeach not initialized error.