[英]Apply function on all elements of list and return a new list based on function's return type
我想通过map
在向量列表上应用 lambda function 并能够从结果中获取布尔列表,然后比较布尔列表中的所有元素
lambda = (\ list x -> distance (x (5,5)) < 10)
[(0,1),(1,6),(15,36)] ->
在每个元素上应用 lambda,这将给出: [True, True, False]
然后检查所有元素是否为True
我试着这样做
checkConvergence :: [Vector] -> Vector -> Bool
checkConvergence list y = map (\ list x -> distance (x y) < 10) list
但我得到了这个:
Couldn't match expected type 'Bool' with actual type [(Vector -> Vector) -> Bool]
三个问题:
\ x ->
而不是\ list x ->
。map
会给你一个Bool
的列表。 如果您想知道它们是否都是真的,那么您需要使用all
代替,或者将结果包装在and
中。Vector
是一些奇怪的 function 类型的别名,否则您的意思可能是distance xy
或distance (x,y)
而不是distance (xy)
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.