我的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