unique elements in a haskell list

前端 未结 7 1952
有刺的猬
有刺的猬 2020-12-13 17:03

okay, this is probably going to be in the prelude, but: is there a standard library function for finding the unique elements in a list? my (re)implementation, for clarificat

7条回答
  •  借酒劲吻你
    2020-12-13 17:57

    Another way to remove duplicates:

    unique :: [Int] -> [Int]
    unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)]
    

提交回复
热议问题