#4370: Bring back monad comprehensions
---------------------------------+------------------------------------------
Reporter: simonpj | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 6.12.3
Keywords: | Testcase:
Blockedby: | Difficulty:
Os: Unknown/Multiple | Blocking:
Architecture: Unknown/Multiple | Failure: None/Unknown
---------------------------------+------------------------------------------
Comment(by simonpj):
Yes, I think this would be a reasonable thing to implement. Provided it
doesn't make the code in the compiler become horrid, I'd be happy to have
this as a patch. It should fit in quite smoothly, and should not affect
people who don't use it. (I'm assuming you intend it as a language
extension. The original objections were indeed solely to do with
unexpected error messages.)
As Max says, much of the machinery is there already. But there are quite
a lot of deatils to think about.
* In the '''renamer''', there is special case code for `mdo`, but
otherwise list comprehensinos and do-notation is handled uniformly. I
think we've deprecated `mdo` in favour of `do {..rec..}`, which would mean
we could get rid of the mdo code altogether, but I'm not sure we've
reached consensus; see #4148. Cleaning up this corner would be v helpful.
* In the '''type checker''', there is special case code for list
comprehensions, separate from do-notation. You could simply use the do-
notation code, but that would lose the `group by` and `zip` stuff, which
only appears in the list comprehension code. So you could:
* Disable the group-by stuff when supporting monad comprehensions; but
that would be annoying when you really want to use group-by in the same
module as a monad comprehension.
* Implement `group by` etc in the monad case too. See Max's comments.
* In the '''desugarer''' there is special desguaring code for list
comprehensions, to get it into foldr/build form. You could probably still
get the same effect by steering the desugaring by the ''types'' rather the
''syntactic form'' of the comprehension.
Things to watch out for
* Rebindable syntax currently works for do-notation but not for list
comprehensions. A natural consequence of the change would be to support
rebindable syntax for comprehensions too, which would be a good thing.
* There is a parallel-array comprehension form too, also handled by the
same code. eg `[: a+1 | a <- as :]`. We don't want to mess it up.
* More surprisingly, guards on a function definition are ''also'' handled
by the same code. Eg
{{{
f x | Just y <- g x
, y>3
= blah
}}}
Here the guards are just `Stmts`, where `Stmt` is the primitive
component of a comprehension. So again, we don't want to mess them up.
I'm happy to advise on this project, but unlikely to take the initiative.
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/4370#comment:2>
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