From: ross Date: Wed, 23 Jun 2004 22:43:21 +0000 (+0000) Subject: [project @ 2004-06-23 22:43:20 by ross] X-Git-Tag: Initial_conversion_from_CVS_complete~1793 X-Git-Url: http://git.megacz.com/?a=commitdiff_plain;h=8000acbfde9bf677123fa28b59835535a2fb1e2f;p=ghc-hetmet.git [project @ 2004-06-23 22:43:20 by ross] arrow notation fixes (problems reported bu John Hughes): * allow an infixexp (exp0) to the left of -<. This adds 4 more shift/reduce conflicts, because it makes if/lambda/let/case/proc before -< ambiguous. This is the same sort of thing as "if x then y else z + 1", and as there shifting does the right thing. * described the grammar more precisely * fixed an example merge to STABLE --- diff --git a/ghc/compiler/parser/Parser.y.pp b/ghc/compiler/parser/Parser.y.pp index 5cc1ca8..4f7890d 100644 --- a/ghc/compiler/parser/Parser.y.pp +++ b/ghc/compiler/parser/Parser.y.pp @@ -59,6 +59,9 @@ Conflicts: 29 shift/reduce, [SDM 19/9/2002] 1 for ambiguity in 'if x then y else z :: T' [State 136] (shift parses as 'if x then y else (z :: T)', as per longest-parse rule) +4 for ambiguity in 'if x then y else z -< e' + (shift parses as 'if x then y else (z -< T)', as per longest-parse rule) + 8 for ambiguity in 'e :: a `b` c'. Does this mean [States 160,246] (e::a) `b` c, or (e :: (a `b` c)) @@ -978,10 +981,10 @@ sigdecl :: { Located (OrdList (LHsDecl RdrName)) } exp :: { LHsExpr RdrName } : infixexp '::' sigtype { LL $ ExprWithTySig $1 $3 } - | fexp '-<' exp { LL $ HsArrApp $1 $3 placeHolderType HsFirstOrderApp True } - | fexp '>-' exp { LL $ HsArrApp $3 $1 placeHolderType HsFirstOrderApp False } - | fexp '-<<' exp { LL $ HsArrApp $1 $3 placeHolderType HsHigherOrderApp True } - | fexp '>>-' exp { LL $ HsArrApp $3 $1 placeHolderType HsHigherOrderApp False} + | infixexp '-<' exp { LL $ HsArrApp $1 $3 placeHolderType HsFirstOrderApp True } + | infixexp '>-' exp { LL $ HsArrApp $3 $1 placeHolderType HsFirstOrderApp False } + | infixexp '-<<' exp { LL $ HsArrApp $1 $3 placeHolderType HsHigherOrderApp True } + | infixexp '>>-' exp { LL $ HsArrApp $3 $1 placeHolderType HsHigherOrderApp False} | infixexp { $1 } infixexp :: { LHsExpr RdrName } diff --git a/ghc/docs/users_guide/glasgow_exts.sgml b/ghc/docs/users_guide/glasgow_exts.sgml index 626cfdd..30de1d2 100644 --- a/ghc/docs/users_guide/glasgow_exts.sgml +++ b/ghc/docs/users_guide/glasgow_exts.sgml @@ -3483,31 +3483,46 @@ using combinators from the module. -The extension adds a new kind of expression for defining arrows, -of the form proc pat -> cmd, +The extension adds a new kind of expression for defining arrows: + +exp10 ::= ... + | proc apat -> cmd + where proc is a new keyword. The variables of the pattern are bound in the body of the proc-expression, which is a new sort of thing called a command. The syntax of commands is as follows: -cmd ::= exp1 -< exp2 - | exp1 -<< exp2 - | do { cstmt1 .. cstmtn ; cmd } - | let decls in cmd - | if exp then cmd1 else cmd2 - | case exp of { calts } - | cmd1 qop cmd2 - | (| aexp cmd1 .. cmdn |) - | \ pat1 .. patn -> cmd - | cmd aexp - | ( cmd ) - -cstmt ::= let decls - | pat <- cmd - | rec { cstmt1 .. cstmtn } - | cmd +cmd ::= exp10 -< exp + | exp10 -<< exp + | cmd0 + +with cmd0 up to +cmd9 defined using +infix operators as for expressions, and + +cmd10 ::= \ apat ... apat -> cmd + | let decls in cmd + | if exp then cmd else cmd + | case exp of { calts } + | do { cstmt ; ... cstmt ; cmd } + | fcmd + +fcmd ::= fcmd aexp + | ( cmd ) + | (| aexp cmd ... cmd |) + +cstmt ::= let decls + | pat <- cmd + | rec { cstmt ; ... cstmt [;] } + | cmd +where calts are like alts +except that the bodies are commands instead of expressions. + + + Commands produce values, but (like monadic computations) may yield more than one value, or none, and may do other things as well. @@ -3692,7 +3707,7 @@ ArrowChoice a => (<+>) :: a e c -> a e c -> a e c so we can use it to build commands: -expr' = proc x -> +expr' = proc x -> do returnA -< x <+> do symbol Plus -< () @@ -3703,6 +3718,9 @@ expr' = proc x -> y <- term -< () expr' -< x - y +(The do on the first line is needed to prevent the first +<+> ... from being interpreted as part of the +expression on the previous line.) This is equivalent to expr' = (proc x -> returnA -< x)