传递lambda函数作为HOF的参数



我有一个这样的函数

f d = foldl (acc x -> acc ++ [distance] where distance = 1) d [1..3]

对于某些GHCI表示:

error: parse error on input ‘where’

where子句适用于声明组,而不适用于表达式。您使用let代替:

(acc x -> let distance = 1 in acc ++ [distance])

最新更新