|
|
|
# Parallel List comprehensions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
See [ExtensionDescriptionHowto](extension-description-howto) for information on how to write these extension descriptions. Please add any new extensions to the list of [HaskellExtensions](haskell-extensions).
|
|
|
|
|
|
|
|
|
|
|
|
## Brief Explanation
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Parallel comprehensions extend list comprehensions with a notation for zips.
|
|
|
|
The comprehension
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
[ e | quals1 | ... | qualsN ]
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
can be desugared to
|
|
|
|
|
|
|
|
|
|
|
|
```wiki
|
|
|
|
zipWithN (\ p1 ... pN -> e) [p1 | quals1] ... [pN | qualsN]
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
where `p`<sub>i</sub> is a tuple of the variables defined by `quals`<sub>i</sub> and used by `e`.
|
|
|
|
|
|
|
|
|
|
|
|
## References
|
|
|
|
|
|
|
|
|
|
|
|
- [ Parallel list comprehensions](http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#parallel-list-comprehensions) in the GHC User's Guide
|
|
|
|
|
|
|
|
## Tickets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<table><tr><th>[\#55](https://gitlab.haskell.org//haskell/prime/issues/55)</th>
|
|
|
|
<td>add Parallel List comprehensions</td></tr></table>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## Pros
|
|
|
|
|
|
|
|
|
|
|
|
- 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.
|
|
|
|
|
|
|
|
## Cons
|
|
|
|
|
|
|
|
|
|
|
|
- Some people do not find them useful, and find the only slightly longer version using explicit zip clearer.
|
|
|
|
- If we went back to monad comprehensions at some point, parallel comprehensions would not make sense.
|
|
|
|
- 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 ([ paper](http://research.microsoft.com/%7Esimonpj/papers/list-comp/index.htm), [ wiki page](http://hackage.haskell.org/trac/ghc/wiki/SQLLikeComprehensions)). Unfortunately GHC's implementation
|
|
|
|
does not currently have the feature enabled due to the difficulty in finding syntax for it that is parsable
|
|
|
|
(see the section on "Bracketing syntax" in the wiki page above). |