I recently came across this function which made me realize I don't understand list comprehensions well. I hope someone can help me understand them better by understanding this example better. The function takes a list of Eq and returns the list of unique elements from it:
unique :: Eq a => [a] -> [a] unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)]
It's using a list comprehension with multiple 'generators' (hope I have the term correctly). My understanding of multiple generators in a list comprehension is that they refine the results of the previous generator.
So the first generator should produce [(Eq,Int)] as input to the second generator? And the second generator should produce [Bool]?
My understanding must be wrong though; how do we end up with just the items where the second generator produced True?