Reputation: 9396
Let's say I have a function a that takes one argument, and a list b with possible inputs, defined as:
let a x1 = x1 == 3
let b = [3, 3]
Now I want to test that all values in b returns True as arguments to a, which I can do with the all function:
all a b
> True
However, can I do something similar if a would take two arguments and b would be a list of tuples where each value in the tuple correspond to each argument?
E.g.:
let a x1 x2 = x1 == 3 && x2 == 1
let b = [(3,1), (3,1)]
all a b
This returns:
<interactive>:1:4:
Couldn't match expected type `Bool'
against inferred type `a1 -> Bool'
In the first argument of `all', namely `a'
In the expression: all a b
In the definition of `it': it = all a b
Any ideas on how to do this?
Upvotes: 2
Views: 112
Reputation: 43393
To turn a function with two arguments into a function expecting one pair, use
uncurry :: (r -> s -> t) -> (r, s) -> t
So, how about
all (uncurry a) b
?
Upvotes: 11