New rebindable syntax for arrows
AbandonedPublic

Authored by jstolarek on Jul 16 2014, 2:53 AM.

Details

Reviewers
simonpj
austin
Trac Issues
#7828
Summary

This is a work in progress on the new desugaring of do-notation for arrows, as proposed by Ross Paterson. This desugaring is will also allow a new RebindableSyntax for arrows. Users will be able to rebing four new arrow operators:

bindA :: Arrow a => a (e,s) b -> a (e,(b,s)) c -> a (e,s) c
u `bindA` f = arr id &&& u >>> arr (\ ((e,s),b) -> (e,(b,s))) >>> f

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

fixA :: ArrowLoop a => a (e,(b,s)) b -> a (e,s) b
fixA f = loop (arr (\ ((e,s),b) -> (e,(b,s))) >>> f >>> arr (\ b -> (b,b)))

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)

Currently the code is incomplete and the DsArrows module is a mess. I'm posting this incomplete code to get some help on implementing the typechecking.

Test Plan

validate + tests that use the new rebinding

Diff Detail

Repository
rGHC Glasgow Haskell Compiler
Branch
T7828-new-rebinding
Lint
Lint ErrorsExcuse: Tabs were already in the code
SeverityLocationCodeMessage
Errorcompiler/hsSyn/HsUtils.lhs:11TXT2Tab Literal
Errorcompiler/rename/RnBinds.lhs:50TXT2Tab Literal
Errorcompiler/typecheck/TcArrows.lhs:18TXT2Tab Literal
Errorcompiler/typecheck/TcMatches.lhs:24TXT2Tab Literal
Unit
No Unit Test Coverage
Build Status
Buildable 26
Build 26: GHC Patch Validation (amd64/Linux)
jstolarek updated this revision to Diff 157.Jul 16 2014, 2:53 AM
jstolarek retitled this revision from to New rebindable syntax for arrows (T7828).
jstolarek updated this object.
jstolarek edited the test plan for this revision. (Show Details)
jstolarek added reviewers: austin, simonpj.

Whoops, Build B24: Diff 157 (D72) has failed! Full logs available at F3832.

Bah, I still haven't fixed that bug. The actual build failure from Harbormaster was:

compiler/deSugar/DsArrows.lhs:792:35:
    Constructor `BodyStmt' should have 3 arguments, but has been given 4
    In the pattern: BodyStmt cmd _ _ c_ty
    In an equation for `dsCmdStmt':
        dsCmdStmt ids local_vars out_ids (BodyStmt cmd _ _ c_ty) env_ids
          = do { (core_cmd, fv_cmd, env_ids1) <- dsfixCmd
                                                   ids local_vars unitTy c_ty cmd;
                 core_mux <- matchEnv
                               env_ids
                               (mkCorePairExpr
                                  (mkCorePairExpr (mkBigCoreVarTup env_ids1) mkCoreUnitExpr)
                                  (mkBigCoreVarTup out_ids));
                 let in_ty = ...
                     ....;
                 .... }
jstolarek added a comment.EditedJul 16 2014, 3:12 AM

I have a simple test case for this new code:

haskell
module T7828 where

import Control.Arrow

test :: Arrow a => a i i
test = proc n -> do
         returnA -< n
         returnA -< n

Compiling it with -dcore-lint leads to an error. The error is (after some clean-up):

Argument value doesn't match argument type:
Fun type:
    arrow (GHC.Prim.Any *, ()) i
    -> arrow (GHC.Prim.Any *, ()) i
    -> arrow (GHC.Prim.Any *, ()) i
Arg type: arrow (i, ()) i
Arg:
     ((>>>) @ (i, ()) @ i @ i
        (arr @ (i, ()) @ i
           (\ (ds2 :: (i, ())) ->
              case ds2 of _ { (ds4, ds5) -> ds4 }))
        (Control.Arrow.returnA @ arrow @ i $dArrow_auX))

*** Offending Program ***
T7828.test  :: forall (arrow :: * -> * -> *) i. Control.Arrow.Arrow arrow => arrow i i
T7828.test = \ (@ (arrow :: * -> * -> *)) (@ i) ($dArrow_auX :: Control.Arrow.Arrow arrow) ->
let {
  arr :: forall b c. (b -> c) -> arrow b c
  arr = Control.Arrow.arr @ arrow $dArrow_auX } in
let {
  (>>>) :: forall a b c. arrow a b -> arrow b c -> arrow a c
  (>>>) = GHC.Desugar.>>> @ arrow $dArrow_auX } in
(>>>) @ i @ (i, ()) @ i
  (arr @ i @ (i, ()) (\ (n :: i) -> (n, ())))
  (thenA @ arrow @ i @ (GHC.Prim.Any *) @ (GHC.Prim.Any *) @ i $dArrow_auX
     ((>>>) @ (i, ()) @ i @ i
        (arr @ (i, ()) @ i
           (\ (ds2 :: (i, ())) ->
              case ds2 of _ { (ds4, ds5) -> ds4 }))
        (Control.Arrow.returnA @ arrow @ i $dArrow_auX))
     ((>>>) @ (i, ()) @ i @ i
        (arr @ (i, ()) @ i
           (\ (ds2 :: (i, ())) ->
              case ds2 of _ { (ds4, ds5) -> ds4 }))
        (Control.Arrow.returnA @ arrow @ i $dArrow_auX)))
compiler/deSugar/DsArrows.lhs
1257

I'm 90% sure that monadic statements (LastStmt. BodyStmt etc.) can be ignored here.

compiler/typecheck/TcArrows.lhs
368–371

I need help here. This typechecking is most likely incorrect as it leads to core lint error.

jstolarek updated this revision to Diff 158.Jul 16 2014, 3:40 AM
jstolarek edited edge metadata.

Fix some lint errors (aka DsArrows formatted to 80 columns)

jstolarek updated this revision to Diff 159.Jul 16 2014, 4:13 AM

Oops, I screwed up while updating the revision. Attempting to fix.

Whoops, Build B26: Diff 159 (D72) has failed! Full logs available at F3897.

Whoops, Build B26: Diff 159 (D72) has failed! Full logs available at F3901.

Whoops, Build B25: Diff 158 (D72) has failed! Full logs available at F3978.

austin retitled this revision from New rebindable syntax for arrows (T7828) to New rebindable syntax for arrows.Aug 21 2014, 12:01 PM
austin updated the Trac tickets for this revision.
austin requested changes to this revision.Oct 17 2014, 7:12 PM
austin edited edge metadata.

Jan, I'm going to block this so it moves out of my 'active' queue since the lint failures need to be addressed. Hopefully @simonpj or someone will be able to take over or swoop in to help.

This revision now requires changes to proceed.Oct 17 2014, 7:12 PM

Any progress on this, @jstolarek?

jstolarek abandoned this revision.Jul 30 2015, 9:17 AM

No, this one is beyond my capabilities.

Fair enough; would you mind marking it as abandoned in this case?

Already marked as abandoned.