[英]How to filter my list of tuples of two input lists?
I am trying to generate all possibles combinations from two lists and then only return those that match the lambda function. So I currently have the following code:我正在尝试从两个列表生成所有可能的组合,然后只返回与 lambda function 匹配的组合。所以我目前有以下代码:
func :: [a] -> [b] -> ((a, b) -> Bool) -> [(a, b)]
func xs ys f = filter f (tup)
where
tup = concat(map (\x -> map (\y -> (x,y))ys) xs)
Currently I am able to generate all the possible combinations, but the filtering won't work.目前我能够生成所有可能的组合,但过滤不起作用。
Error for the input: func [1,2,3] [4,5] (\ ab -> a+b > 6)
输入错误: func [1,2,3] [4,5] (\ ab -> a+b > 6)
• Couldn't match expected type 'Bool' with actual type '(a, b) -> Bool'
• The lambda expression '\ ab -> a + b > 7' has two value arguments, but its type '(a, b) -> Bool' has only one
How can I solve this?我该如何解决这个问题?
I tried to use map
instead of filter
, but that did not work as well.我尝试使用map
而不是filter
,但效果不佳。
Making a function with two arguments and making a function with a single 2-tuple argument use slightly different syntax:使用两个 arguments 制作 function 和使用单个二元组参数制作 function 使用略有不同的语法:
\a b -> a+b > 6 -- two arguments
\(a, b) -> a+b > 6 -- one tuple argument
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.