简体   繁体   English

使用all with multi argument函数

[英]Using all with multi argument function

Let's say I have a function a that takes one argument, and a list b with possible inputs, defined as: 假设我有一个带有一个参数的函数a和一个带有可能输入的列表b,定义如下:

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: 现在我想测试b中的所有值都返回True作为a的参数,我可以使用all函数:

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? 但是,如果a将采用两个参数并且b将是元组列表,其中元组中的每个值对应于每个参数,我可以执行类似的操作吗?

Eg: 例如:

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? 关于如何做到这一点的任何想法?

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

?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM