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)))
Couldn't match expected type
[a]
with actual type[a0] -> [a0]
In the return type of a call ofnub'
Probable cause:nub'
is applied to too few arguments In the expression:nub' l []
In an equation fornub
: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)))
Couldn't match expected type
[a0] -> [a0]
with actual type[a1]
In the second argument ofnub'
, namely[]
In the expression:nub' l []
In an equation fornub
: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)))
Why it doesn't work? I cannot understand. Please give me a hand. The errors are understandable but I don't know their causes.