[Haskell-cafe] Most elegant funciton for removing adjacent duplicates from a list using foldl and foldr

2009-03-15 Thread R J
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:

Re: [Haskell-cafe] Most elegant funciton for removing adjacent duplicates from a list using foldl and foldr

2009-03-15 Thread Sebastian Sylvan
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

Re: [Haskell-cafe] Most elegant funciton for removing adjacent duplicates from a list using foldl and foldr

2009-03-15 Thread Roel van Dijk
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

Re: [Haskell-cafe] Most elegant funciton for removing adjacent duplicates from a list using foldl and foldr

2009-03-15 Thread Peter Verswyvelen
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

Re: [Haskell-cafe] Most elegant funciton for removing adjacent duplicates from a list using foldl and foldr

2009-03-15 Thread wren ng thornton
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