
Unsubscribe Sent from my iPad
On Apr 26, 2020, at 8:51 AM, Ken Overton
wrote: Hello all,
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?
Thanks,
-- Ken Overton (917) 863-3937 ken.overton@gmail.com
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (1)
-
Christopher Ledbetter