I need to write an implementation using foldl, and a separate implementation
using foldr, of a function, remdups xs, that removes adjacent duplicate items
from the list xs. For example, remdups [1,2,2,3,3,3,1,1]= [1,2,3,1].
My approach is first to write a direct recursion, as follows:
2009/3/15 R J rj248...@hotmail.com
I need to write an implementation using foldl, and a separate
implementation using foldr, of a function, remdups xs, that removes
adjacent duplicate items from the list xs. For example, remdups
[1,2,2,3,3,3,1,1]= [1,2,3,1].
My approach is first to write
2009/3/15 R J rj248...@hotmail.com:
What, if any, is the implementation using only two cases?
This version considers 2 cases 2 times :-) But only the 'go' function
is recursive, so it could probably be written using some kind of fold.
The value being build by the fold should probably be some
Why don't you just swap the pattern match order?
remdups :: (Eq a) = [a] - [a]
remdups (x : xx : xs) = if x == xx then remdups (x : xs) else x :
remdups (xx : xs)
remdups xs= xs
This should cover all cases no?
Also I prefer guards, but I guess that is personal
R J wrote:
I need to write an implementation using foldl, and a separate implementation using foldr,
of a function, remdups xs, that removes adjacent duplicate items from the
list xs. For example, remdups [1,2,2,3,3,3,1,1]= [1,2,3,1].
My approach is first to write a direct recursion, as