unique elements in a haskell list

前端 未结 7 1969
有刺的猬
有刺的猬 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:54

    I think this would do it.

    unique [] = []
    unique (x:xs) = x:unique (filter ((/=) x) xs)
    

提交回复
热议问题