
#10843: Allow do blocks without dollar signs as arguments -------------------------------------+------------------------------------- Reporter: agibiansky | Owner: agibiansky Type: feature request | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.10.2 (Parser) | Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Revisions: -------------------------------------+------------------------------------- Comment (by goldfire): Replying to [comment:3 nomeata]:
Is there code that is valid with and without your extension, but with different semantics?
To me, this is the key question. I can't think of any. But let's dig deeper. I'm looking at the [https://www.haskell.org/onlinereport/haskell2010/haskellch3.html#x8-220003 Haskell 2010 Report] for parsing these sorts of things. Here's the relevant bit: {{{ exp → infixexp :: [context =>] type (expression type signature) | infixexp infixexp→ lexp qop infixexp (infix operator application) | - infixexp (prefix negation) | lexp lexp → \ apat1 … apatn -> exp (lambda abstraction, n ≥ 1) | let decls in exp (let expression) | if exp [;] then exp [;] else exp (conditional) | case exp of { alts } (case expression) | do { stmts } (do expression) | fexp fexp → [fexp] aexp (function application) aexp → qvar (variable) | gcon (general constructor) | literal | ( exp ) (parenthesized expression) | ( exp1 , … , expk ) (tuple, k ≥ 2) | [ exp1 , … , expk ] (list, k ≥ 1) | [ exp1 [, exp2] .. [exp3] ] (arithmetic sequence) | [ exp | qual1 , … , qualn ] (list comprehension, n ≥ 1) | ( infixexp qop ) (left section) | ( qop⟨-⟩ infixexp ) (right section) | qcon { fbind1 , … , fbindn } (labeled construction, n ≥ 0) | aexp⟨qcon⟩ { fbind1 , … , fbindn } (labeled update, n ≥ 1) }}} From this grammar, I was inspired to try the following silliness: {{{ {-# LANGUAGE Haskell2010 #-} instance Num (IO ()) where negate = id main = - do putStrLn "hi" }}} (Note the `-` after the `main =`.) This fails with a parse error. I'd love for someone else to check this against the grammar and see if I should report a separate bug. How does this work in the patch supplied? In any case, even looking at the grammar, it looks like you've found a spot free in the grammar. How many shift/reduce conflicts does the grammar have? At last check, GHC's parser had 47. This isn't great, but we don't want to increase this number! Thanks for submitting a patch! -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/10843#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler