Changes between Version 1 and Version 2 of Ticket #7828, comment 6


Ignore:
Timestamp:
May 29, 2014 1:31:27 PM (5 years ago)
Author:
jstolarek
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #7828, comment 6

    v1 v2  
    1 I have spent some time on this today and I have some questions. As I understand Simon's comment the idea is to handle the arrow do-notation similarly to the monadic do-notation. Looking at the handling of monadic bind I see that indeed each `BindStmt` stores a unique call to `>>=` and `fail`. These are [https://github.com/ghc/ghc/blob/master/compiler/rename/RnExpr.lhs#L681 generated in the renamer] and then [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsExpr.lhs#L775 converted to explicit lambda by the desugarer]. For arrow operations - `arr`, `(>>>)`, `first` and possibly `loop`, `(|||)` and `app` - [https://github.com/ghc/ghc/blob/master/compiler/rename/RnExpr.lhs#L416 renamer creates a shared table of names]. [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsArrows.lhs#L69 Desugarer creates a command environment] that contains identifiers that are shared by all desugared expressions. This basicaly rephrases what Simon wrote. Now I have reached a point where I'm not sure what to do. For monads calls to bind are introduced only (?) when we encounter `BindStmt`. For arrows it is not that simple. For example calls to `>>>` are introduced when we desugar `BodyStmt`, `BindStmt` and `RecStmt` but also by [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsArrows.lhs#L94 do_compose], which does not correspond to any particular source construct but is called in many places of arrow notation desugarer. Another place where we introduce `>>>` is [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsArrows.lhs#L1038 desugaring of CmdLStmt]. I might be wrong, but it seems to me that adding `SyntaxExpr` to `HsCmd` constructors won't help us here. We need a way of generating fresh calls to desugared arrow operations out of thin air.
     1I have spent some time on this today and I have some questions. As I understand Simon's comment the idea is to handle the arrow do-notation similarly to the monadic do-notation. Looking at the handling of monadic bind I see that indeed each `BindStmt` stores a unique call to `>>=` and `fail`. These are [https://github.com/ghc/ghc/blob/master/compiler/rename/RnExpr.lhs#L681 generated in the renamer] and then [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsExpr.lhs#L775 converted to explicit lambda by the desugarer]. For arrow operations - `arr`, `(>>>)`, `first` and possibly `loop`, `(|||)` and `app` - [https://github.com/ghc/ghc/blob/master/compiler/rename/RnExpr.lhs#L416 renamer creates a shared table of names]. [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsArrows.lhs#L69 Desugarer creates a command environment] that contains identifiers that are shared by all desugared expressions. This basicaly rephrases what Simon wrote. Now I have reached a point where I'm not sure what to do. For monads calls to bind are introduced only (?) when we encounter `BindStmt`. For arrows it is not that simple. For example calls to `>>>` are introduced when we desugar `BodyStmt`, `BindStmt` and `RecStmt` but also by [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsArrows.lhs#L123 do_premap], which does not correspond to any particular source construct but is called in many places of arrow notation desugarer. Another place where we introduce `>>>` is [https://github.com/ghc/ghc/blob/master/compiler/deSugar/DsArrows.lhs#L1038 desugaring of CmdLStmt]. I might be wrong, but it seems to me that adding `SyntaxExpr` to `HsCmd` constructors won't help us here. We need a way of generating fresh calls to desugared arrow operations out of thin air.
    22
    33I also don't understand why is arrow notation [https://github.com/ghc/ghc/blob/master/compiler/rename/RnExpr.lhs#L803 considered not rebindable]? The comment suggests that this is because !DsArrows performs a separate desugaring of arrow notation. Am I right to think that after this change is implemented arrow notation will be marked as rebindable?