0
belongs :: Eq a => a -> [a] -> [a]
belongs e (h:t) = if (h == e) then [] else belongs e t
belongs e [] = [e]
nub :: Eq a => [a] -> [a]
nub l = nub' l []
where
nub' [] new_list = new_list
nub' (x:xs) new_list = (nub' xs ((\ e new_list ->
case (belongs e new_list) of
[] -> new_list
(h:t) -> (h:new_list))(x new_list)))
無法匹配,期望與實際類型
[a0] -> [a0]
型[a]
在 返回類型的nub'
可能的原因調用的:nub'
應用於 參數太少在表達式:nub' l []
在爲nub
的公式:預計衝突和實際參數nub l = nub' l [] where nub' [] new_list = new_list nub' (x : xs) new_list = (nub' xs ((\ e new_list -> case (belongs e new_list) of { [] -> ... (h : t) -> ... }) (x new_list)))
無法比擬預期型
[a0] -> [a0]
與ACTU人型[a1]
在 的nub'
,即[]
在表達式中的第二個參數:nub' l []
在方程nub
:nub l = nub' l [] where nub' [] new_list = new_list nub' (x : xs) new_list = (nub' xs ((\ e new_list -> case (belongs e new_list) of { [] -> ... (h : t) -> ... }) (x new_list)))
爲什麼它不工作?我不明白。請給我一個手。 錯誤是可以理解的,但我不知道它們的原因。