I think that unique should return a list of elements that appear only once in the original list; that is, any elements of the source list that appear more than once should not be included in the result.
You can suggest an alternative definition, unique_alt:
unique_alt :: [Int] -> [Int] unique_alt [] = [] unique_alt (x:xs) | elem x ( unique_alt xs ) = [ y | y <- ( unique_alt xs ), y /= x ] | otherwise = x : ( unique_alt xs )
Here are a few examples that highlight the differences between unique_alt and unqiue:
unique [1,2,1] = [2,1] unique_alt [1,2,1] = [2] unique [1,2,1,2] = [1,2] unique_alt [1,2,1,2] = [] unique [4,2,1,3,2,3] = [4,1,2,3] unique_alt [4,2,1,3,2,3] = [4,1]
Adam Grant Aug 10 2018-12-12T00: 00Z
source share