2013-11-02 46 views
1

我在想,爲什麼不這項工作(2個誤差修改):與故障,其中如果表達式

removeCard cardList card e = 
    if length $ (filter` cardList) == (length cardList) 
    -- the same error 
    -- if length $ filter` cardList == length cardList 
    -- if (length $ filter` cardList) == (length cardList) 
    then error "The error occured" 
    else filter` cardList 
    where 
    filter` [] = [] 
    filter` (x:xs) = if x == card then xs else x : filter` xs 

如果我只是一個簡單的表達像if 1 == 2 ...替換如果,我會得到另一個錯誤:

parse error on input `where' 

回答

3

不要在「filter prime」的名稱中使用反引號。使用單引號來代替:

​​

反引號用來指示非符號功能名稱中綴表示法。

2

反引號(`)在標識符中不是合法字符。它們用於編寫普通二進制函數作爲中綴運算符,如

(== card) `filter` cardList 

您可能想要使用素數(')。

removeCard cardList card e = 
    if length $ (filter' cardList) == (length cardList) 
    then error "The error occured" 
    else filter' cardList 
    where 
    filter' [] = [] 
    filter' (x:xs) = if x == card then xs else x : filter' xs