[GHC] #7828: RebindableSyntax and Arrow

GHC ghc-devs at haskell.org
Tue Jun 3 23:43:16 UTC 2014


#7828: RebindableSyntax and Arrow
----------------------------------------------+----------------------------
        Reporter:  AlessandroVermeulen        |            Owner:
            Type:  bug                        |  jstolarek
        Priority:  normal                     |           Status:  new
       Component:  Compiler (Type checker)    |        Milestone:  7.10.1
      Resolution:                             |          Version:  7.6.2
Operating System:  Unknown/Multiple           |         Keywords:
 Type of failure:  GHC rejects valid program  |     Architecture:
       Test Case:                             |  Unknown/Multiple
        Blocking:                             |       Difficulty:  Unknown
                                              |       Blocked By:
                                              |  Related Tickets:
----------------------------------------------+----------------------------

Comment (by ross):

 Here's a different suggestion for rebinding that is perhaps more analogous
 to the expression case.  We could consider do and if commands as sugar for
 more primitive commands:
 {{{
 do { p <- cmd; stmts } = cmd `bind` \ p -> do { stmts }
 do { cmd; stmts } = cmd `bind_` do { stmts }
 do { let defs; stmts } = let defs in do { stmts }
 do { cmd } = cmd
 if exp then cmd1 else cmd2 = (| ifThenElseA cmd1 cmd2 |) exp
 }}}
 (remember these are commands, not expressions), given the ordinary Haskell
 definitions
 {{{
 bind :: Arrow a => a (e,s) b -> a (e,(b,s)) c -> a (e,s) c
 u `bind` f = arr id &&& u >>> arr (\ ((e,s),b) -> (e,(b,s))) >>> f

 bind_ :: Arrow a => a (e,s) b -> a (e,s) c -> a (e,s) c
 u `bind_` v = arr id &&& u >>> arr fst >>> v

 ifThenElseA :: ArrowChoice a => a (e,s) r -> a (e,s) r -> a (e,(Bool,s)) r
 ifThenElseA thenPart elsePart = arr split >>> thenPart ||| elsePart
   where
     split (e, (True, s)) = Left (e, s)
     split (e, (False, s)) = Right (e, s)
 }}}
 Then rebinding would just use whatever definitions of these names are in
 scope, and they could be associated with {{{BindStmt}}}, etc, in a similar
 way to expressions.  But would this be enough for the people who want
 rebinding?

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/7828#comment:17>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list