[Haskell-cafe] Newbie syntax question
gale at sefer.org
Sun Sep 18 03:51:15 EDT 2005
> map (foo 5) my_list_of_lists_of_doubles
> ...But how to do that (if possible) when I
>invert the parameters list ?!
Let me add one more solution, and then summarize:
The problem disapears if you use a list
comprehension instead of map:
[foo x 5 | x <- my_list_of_lists_of_doubles]
List comprehensions are funny. Sometimes, they
are powerful, consise, and crystal clear. Other
times they can seem wordy and confusing. In
this case it works well.
OK, so the four solutions that have been suggested
1. map (flip foo 5) my_list_of_lists_of_doubles
2. map (`foo` 5) my_list_of_lists_of_doubles
3. map (\x->foo x 5) my_list_of_lists_of_doubles
4. [foo x 5 | x <- my_list_of_lists_of_doubles]
(1) and (2) are closest to what you originally
wanted to write. They do not neatly generalize
beyond the second parameter.
(3) is more general - but a little less clear.
(4) is the most different from your original
idea. In a certain sense, it is even more general
than (3). In this case, it is also simple and
clear - though you may not always be so lucky.
BTW - great question!
More information about the Haskell-Cafe