count :: Eq a => a -> [a] -> Int
count _[] = 0
count z (x:xs) | z == x = 1 + (count z xs)
| otherwise = count z xs
rmdups :: Eq a => [a] -> [a]
rmdups [] = []
rmdups (x:xs) | count x xs > 0 = rmdups xs
| otherwise = x: rmdups xs
上述編譯代碼,但是當我輸入'ababca'
rmdups的輸出爲'bca'
,我希望它是'abc'
。爲什麼一個去那裏?我一直在改變這些代碼,不知道爲什麼它會這樣做。這爲什麼不給出正確的輸出?