[英]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.