[Haskell-beginners] Unsubscribe

Christopher Ledbetter cledbetter1 at yahoo.com
Mon Apr 27 12:08:45 UTC 2020


Sent from my iPad

> On Apr 26, 2020, at 8:51 AM, Ken Overton <ken.overton at gmail.com> 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 at gmail.com
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20200427/30f29f33/attachment.html>

More information about the Beginners mailing list