monad comprehensions

Monad comprehensions

After a long absence, monad comprehensions are back, thanks to George Giorgidze and his colleagues. With {-# LANGUAGE MonadComprehensions #-} the comprehension [f x | x <- xs, x>4 ] is interpreted in an arbitrary monad, rather than being restricted to lists. Not only that, it also generalises nicely for parallel/zip and SQL-like comprehensions. The aforementioned generalisations can be turned on by enabling the MonadComprehensions extension in conjunction with the ParallelListComp and TransformListComp extensions.

Rebindable syntax is fully supported for standard monad comprehensions with generators and filters. We also plan to allow rebinding of the parallel/zip and SQL-like monad comprehension notations.

Note that the actual implementation is not using the do-Notation, it's only used here to give a basic overview about how the translation works.

Implementation details

Monad comprehensions had to change the StmtLR data type in the hsSyn/HsExpr.lhs file in order to be able to lookup and store all functions required to desugare monad comprehensions correctly (e.g. return, (>>=), guard etc). Renaming is done in rename/RnExpr.lhs and typechecking in typecheck/TcMatches.lhs. The main desugaring is done in deSugar/DsListComp.lhs. If you want to start hacking on monad comprehensions I'd look at those files first.