how do you change the following haskell code into a high order function? -
define function
rmdups :: eq => [a] -> [a] that removes duplicates list. example, rmdups "ababca" should return "abc". order of elements in output list not important
here have done far: works:
rmdups :: eq => [a] -> [a] rmdups [] = [] rmdups (x:xs) = x : rmdups (filter(/= x) xs) this not work, doing wrong:
rmdups = map head . group . sort
you this:
import data.list (nub) rmdups = nub but assume you're not allowed.
otherwise, solution (rmdups = map head . group . sort) works me.
if compiler says group or sort not in scope, import data.list.
ps: believe meant "point free style", not "higher order function"
edit: user3217013 pointing that out.
Comments
Post a Comment