[GHC] #7828: RebindableSyntax and Arrow
GHC
cvs-ghc at haskell.org
Fri Apr 12 13:44:09 CEST 2013
#7828: RebindableSyntax and Arrow
------------------------------------+---------------------------------------
Reporter: AlessandroVermeulen | Owner:
Type: bug | Status: new
Priority: normal | Milestone:
Component: Compiler | Version: 7.6.2
Keywords: | Os: Unknown/Multiple
Architecture: Unknown/Multiple | Failure: GHC rejects valid program
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
------------------------------------+---------------------------------------
Changes (by simonpj):
* difficulty: => Unknown
Comment:
I know exactly what is happening here, but need some arrow-aware person to
do some work to fix it.
Remember that GHC typechecks the user-written '''source code''' not the
desugared code.
What shouuld happen is that at each source-code construct that requires
(say) a use of `(>>>)`, we should instantiate a fresh call of `(>>>)`, and
attach that instantiated call to the syntax tree. That's what happens for
monads. For example, here is the data type of `Stmt` (in `HsExpr`):
{{{
data StmtLR idL idR body -- body should always be (LHs**** idR)
= LastStmt -- Always the last Stmt in ListComp, MonadComp, PArrComp,
-- and (after the renamer) DoExpr, MDoExpr
-- Not used for GhciStmtCtxt, PatGuard, which scope over
other stuff
body
(SyntaxExpr idR) -- The return operator, used only for
MonadComp
-- For ListComp, PArrComp, we use the
baked-in 'return'
-- For DoExpr, MDoExpr, we don't appply
a 'return' at all
-- See Note [Monad Comprehensions]
| BindStmt (LPat idL)
body
(SyntaxExpr idR) -- The (>>=) operator; see Note [The type of
bind]
(SyntaxExpr idR) -- The fail operator
-- The fail operator is noSyntaxExpr
-- if the pattern match can't fail
...etc...
}}}
The `SyntaxExpr` on the `ReturnStmt` is for the instantiated call of
`return`; the ones on `BindStmt` are for `(>>=)` and `fail`.
But currently for arrow `Cmd`s we use a different (older) plan. We have a
'''single''' instantiated call of `(>>>)` for the whole `Cmd`. It is held
in the `CmdTop`:
{{{
data HsCmdTop id
= HsCmdTop (LHsCmd id)
PostTcType -- Nested tuple of inputs on the
command's stack
PostTcType -- return type of the command
(CmdSyntaxTable id) -- See Note [CmdSyntaxTable]
}}}
The `CmdSyntaxTable` has the calls for `(>>>)`, `first` etc.
But this approach requires `(>>>)` etc to be fully polymorphic in the non-
arrow argument, so that this one call can be used at every place in the
command that it's needed. And yours are not.
Solution: use the same approach as we use for monads:
* Get rid of the `CmdSyntaxTable` on HsCmdTop`
* Add `SyntaxExpr` fields to all the appropriate constructs in `HsCmd`
that need them.
I don't think this is really hard, but it's a bit fiddly. I'd be happy to
advise if someone wants to undertake it.
Simon
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/7828#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list