|Version 7 (modified by simonmar@…, 6 years ago) (diff)|
Parallel List comprehensions
Parallel comprehensions extend list comprehensions with a notation for zips. The comprehension
[ e | quals1 | ... | qualsN ]
can be desugared to
zipWithN (\ p1 ... pN -> e) [p1 | quals1] ... [pN | qualsN]
where pi is a tuple of the variables defined by qualsi and used by e.
- Parallel list comprehensions in the GHC User's Guide
- add Parallel List comprehensions
- Easy and well-specified.
- Expresses zips of filters, which are tricky to express with standard list comprehensions.
- Those who use them do so heavily, e.g. there are 142 uses of parallel list comprehensions in the jhc source tree.
- Some people do not find them useful, and find the only slightly longer version using explicit zip clearer.
- One more concept to learn (and implement), with relatively low payoff.
- Cannot express filters of zips. If you want to filter the list returned by a parallel list comprehension, you have to go back to using the zip form, or separately filter the result.
- Might cause confusing errors if an extra | is typed by accident.
- GHC has a more general mechanism in the form of Comprehensive Comprehensions