#6038: Allow view patterns inside record patterns
---------------------------------+------------------------------------------
Reporter: akio | Owner:
Type: feature request | Status: new
Priority: normal | Milestone: _|_
Component: Compiler | Version: 7.4.1
Keywords: | Os: Unknown/Multiple
Architecture: Unknown/Multiple | Failure: None/Unknown
Difficulty: Unknown | Testcase:
Blockedby: | Blocking:
Related: |
---------------------------------+------------------------------------------
Changes (by simonpj):
* difficulty: => Unknown
* milestone: => _|_
Comment:
I agree that would be nice. At the moment view patterns must have parens
around them, and for a good reason. Consider a case with a view pattern:
{{{
case c of
(ch -> Just y) -> y
}}}
Now imagine it without parens
{{{
case c of
ch -> Just y -> y}}}
}}}
and you can see that you'd need a lot of lookahead to spot where the
pattern ends.
There's probably a way to work this out (require parens just for view
patterns in a case or lambda pattern, somehow?). If anyone would like to,
please go ahead and propose (and test!) a patch to the parser.
Thinking it might be easy, I tried the diff below, but it doesn't work for
the above reason. So I'm backing off.
{{{
diff --git a/compiler/parser/Parser.y.pp b/compiler/parser/Parser.y.pp
index 04c858a..7da62f7 100644
--- a/compiler/parser/Parser.y.pp
+++ b/compiler/parser/Parser.y.pp
@@ -1376,6 +1376,7 @@ exp :: { LHsExpr RdrName }
| 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 '->' exp { LL $ EViewPat $1 $3 }
| infixexp { $1 }
infixexp :: { LHsExpr RdrName }
@@ -1534,7 +1535,7 @@ texp :: { LHsExpr RdrName }
| qopm infixexp { LL $ SectionR $1 $2 }
-- View patterns get parenthesized above
- | exp '->' texp { LL $ EViewPat $1 $3 }
+-- | exp '->' texp { LL $ EViewPat $1 $3 }
}}}
--
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/6038#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
_______________________________________________
Glasgow-haskell-bugs mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs