I wanted to answer this question using until. But this does not work, and I came to the conclusion that I do not understand until.
So, I take the function given by OP, verbatim:
removeAdjDups :: (Eq a) => [a] -> [a]
removeAdjDups [] = []
removeAdjDups [x] = [x]
removeAdjDups (x : y : ys)
| x == y = removeAdjDups ys
| otherwise = x : removeAdjDups (y : ys)
Then I write a function True/Falsethat returns if there is a duplicate:
hasAdjDups :: (Eq a) => [a] -> Bool
hasAdjDups [] = False
hasAdjDups [x] = False
hasAdjDups (x : y : ys)
| x == y = True
| otherwise = hasAdjDups (y : ys)
Finally, I use untilas follows:
f :: (Eq a) => [a] -> [a]
f x = until hasAdjDups removeAdjDups x
And this does not work:
> hasAdjDups "aabccddcceef"
True
> removeAdjDups "aabccddcceef"
"bf"
> f "aabccddcceef"
"aabccddcceef"
Am I misunderstanding until, or have I made a mistake?
source
share