#4370: Bring back monad comprehensions
---------------------------------+------------------------------------------
Reporter: simonpj | Owner: nsch
Type: feature request | Status: new
Priority: normal | Milestone: 7.2.1
Component: Compiler | Version: 6.12.3
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by nsch):
Good news! I'm almost done with the implementation. Monad comprehensions
now support:
* Binding statements: `[ x + y | x <- Just 1, y <- Just 2 ]` => `Just 3`
* Guards: `[ x | x <- [1..5], x <= 3 ]` => `[1,2,3]`
* Transform statements: `[ x | x <- [1..5], then take 2 ]` => `[1,2]`
* Grouping statements: `[ x | x <- [1,1,2,2,3,3], then group by x ]` =>
`[[1,1],[2,2],[3,3]]`
* Parallel/zip statements: `[ (x,y) | x <- [1,2] | y <- [3,4] ]` =>
`[(1,3),(2,4)]`
All these features are enabled by default if you use the
`MonadComprehensions`
language flag. Note, that there are different requirements for some of
those statements:
* Guards require a `MonadPlus` instance since it's using `guard` from
`Control.Monad`
* Grouping requires a `MonadGroup` instance, a new type class which we
added
to the `base` package (unless you use a different grouping function
via
`then group by x using ..`)
* Parallel statements require a `MonadZip` instance, another new type
class
for the `base` package.
At least for now, both new type classes were put into `base` since they're
supposed to be used by the endusers (people might come up with their own
groupable/zipable monads). If you have any concerns with that I could move
them
out of `base` into another package of course.
In the next couple of days I'll clean up the code a bit, add/complete the
documentation, add some tests to the testsuite and finally merge our
working
repo with current head before I sent in those patches (you want git
patches,
right?).
As usual - if you have any concerns, please let me know!
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4370#comment:35>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs