我的Haskell代码如下所示功能ELEM抛出错误
isNotPrime x = elem 0 map (mod x)[3.. (x-1)]
在编译时就说明这些错误
Couldn't match expected type ‘(t1 -> t1) -> [t1] -> t’
with actual type ‘Bool’
The function ‘elem’ is applied to four arguments,
but its type ‘([a0] -> [b0])
-> ((a0 -> b0) -> [a0] -> [b0]) -> Bool’
has only two
In the expression: elem 0 map (mod x) [3 .. (x - 1)]
In an equation for ‘prime’:
prime x = elem 0 map (mod x) [3 .. (x - 1)]
我的理解是,ELEM接受两个参数,我不明白我怎么在上面的代码中传递4个参数,因为map函数应该只返回一个列表。
很好的解释!谢谢。这工作。 – rt88