haskell - Exception: Non-exhaustive patterns in function -
attempting create function removes duplicates list, , replaces them single element. keep getting error message "non-exhaustive patterns in function removeduplicate". assume means pattern matching missing possible case? think i've covered possibilities though. i'm new haskell, appreciated.
removeduplicate :: (eq a) => [a] -> [a] removeduplicate [] = [] removeduplicate (x:[]) = [x] removeduplicate (x:z:[]) = if z == x [x] else (x:z:[]) removeduplicate (x:y:[xs]) | x == y = x:(removeduplicate [xs]) | otherwise = x:y:(removeduplicate [xs])
your problem in final pattern. assume meant match lists, way have it, matching list 1 element, xs, in it.
this means compiler seeing match 3 element list, not arbitrary length list, why complaining.
to fix this, remove box around xs.
removeduplicate (x:y:xs) | x == y = x:(removeduplicate xs) | otherwise = x:y:(removeduplicate xs) now xs treated list, matching lists at least 3 items, rather 3 items.
Comments
Post a Comment