[Haskell-cafe] [ANNOUNCE] comprehensions-ghc: ApplicativeComprehensions as a GHC plugin

Matthew Farkas-Dyck strake888 at gmail.com
Tue Apr 9 00:31:49 UTC 2019


https://hackage.haskell.org/package/comprehensions-ghc

See description for instructions how to use.

A comprehension makes more sense than a `do` expression for
`Applicative` types — `ApplicativeDo` relies on a kludge: checking
whether the last expression has the form `pure _` or `return _`.
Indeed, for an `Applicative` term, it can ultimately (modulo aliases,
let-expressions, η-expansion, etc) have no other!

So far, however, the plugin merely rewrites each comprehension as a
`do` expression. (It ignores comprehensions with features which can't
be converted.)

My most compelling use case so far has been context-free-parsing
records (for examples: with `optparse-applicative` or
`regex-applicative`). It lets one write the following: `[Options {..}
| foo <- parseFoo, bar <- parseBar]`

Cheers, happy hacking ☺


More information about the Haskell-Cafe mailing list