[erlang-questions] Second order function lists:map

Franco Milicchio <>
Tue Mar 10 15:56:23 CET 2009


Hi everyone!

I am trying to write two small functions employing the lists package,  
and now I am wondering how to proceed. My functions are quite  
straightforward: I want two second-order functions that "abstract"  
lists:map.

The first one is a function that applies a given function to a list of  
arguments. So, a first application gives me a function, and this  
applied to a list gives me the mapping of my function over the list. I  
have succeeded in doing this function and it seems to work:

paa(F) ->
     fun(L) ->
             lists:map(F, L)
     end.

41> PP=p:paa(fun math:sin/1).
#Fun<p.1.71425429>

42> PP(lists:seq(0,100)).
[0.0,0.8414709848078965,0.9092974268256817,
  0.1411200080598672,-0.7568024953079282,-0.9589242746631385,
  -0.27941549819892586,0.6569865987187891,0.9893582466233818,
  0.4121184852417566,-0.5440211108893699,-0.9999902065507035,
  -0.5365729180004349,0.4201670368266409,0.9906073556948704,
  0.6502878401571169,-0.2879033166650653,-0.9613974918795568,
  -0.750987246771676,0.14987720966295234,0.9129452507276277,
  0.836655638536056,-0.008851309290403876,-0.8462204041751706,
  -0.9055783620066239,-0.13235175009777303,0.7625584504796028,
  0.956375928404503,0.27090578830786904|...]


The second one is tricky to me (I am not an erlang guru!). I want its  
"dual", so given a list of functions, I'd like to map them to a single  
argument, writing a second-order function like the above p:paa/1. The  
only problem is that I am stopped by this problem, I know it's easy  
but I am not that good at functional programming :)

Thanks for any help!


-- 
Franco Milicchio <>

DIA - Dept. of Computer Science and Engineering
University Roma Tre
http://plm.dia.uniroma3.it/milicchio/

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2435 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090310/8fbd7668/attachment.bin>


More information about the erlang-questions mailing list