<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto">Unsubscribe<br><br><div dir="ltr">Sent from my iPad</div><div dir="ltr"><br><blockquote type="cite">On Apr 26, 2020, at 8:51 AM, Ken Overton <ken.overton@gmail.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr">Hello all,<div><br></div><div>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:<br><br> unique :: Eq a => [a] -> [a]<br> unique xs = [x | (x,y) <- zip xs [0..], x `notElem` (take y xs)]<br><br>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.<br><br>So the first generator should produce [(Eq,Int)] as input to the second generator? And the second generator should produce [Bool]?<br><br>My understanding must be wrong though; how do we end up with just the items where the second generator produced True?<br><br>Thanks,<font color="#888888"><br><div><br></div></font></div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div>Ken Overton</div><div>(917) 863-3937</div><div><a href="mailto:ken.overton@gmail.com" target="_blank">ken.overton@gmail.com</a></div><div><br></div></div></div>
<span>_______________________________________________</span><br><span>Beginners mailing list</span><br><span>Beginners@haskell.org</span><br><span>http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</span><br></div></blockquote></body></html>