I would like to change this:
add a b =
a + b
List.map2 add [1,2] [3,4]
With something like this:
List.map2 (\(a , b ) -> a + b) [1,2] [3,4]
Possible?
Yes, the problem you are encountering is that your lambda is defined as accepting a tuple of (a, b)
rather than two parameters. This is what you want to write (notice the lack of parentheses and comma in the lambda argument):
List.map2 (\a b -> a + b) [1,2] [3,4]
Since there are two arguments, and +
takes two arguments, you could take advantage of the ability to make infix operators into regular functions by wrapping them in parentheses (as shown in the docs), and slim this down by writing it like this:
List.map2 (+) [1,2] [3,4]