-1

Define a function

rmdups :: Eq a => [a] -> [a]

that removes duplicates from a list. For example, rmdups "ababca" should return "abc". The order of the elements in the output list is not important

Here is what I have done so far: This works:

 rmdups :: Eq a => [a] -> [a]
 rmdups [] = []
 rmdups (x:xs) = x : rmdups (filter(/= x) xs)

This does not work, what am I doing wrong:

 rmdups = map head . group . sort
Cactus
  • 27,075
  • 9
  • 69
  • 149
B.John
  • 1
  • 1
  • 2

1 Answers1

2

You could do this:

import Data.List (nub)
rmdups = nub

But I assume that you're not allowed.

Otherwise, your solution (rmdups = map head . group . sort) works for me.

If the compiler says group or sort not in scope, just import it from Data.List.

PS: I believe you meant "point free style", not "higher order function"

Edit: Thanks user3217013 for pointing that out.

Community
  • 1
  • 1
baxbaxwalanuksiwe
  • 1,474
  • 10
  • 20