[GHC] #8387: View patterns + pattern bindings: finnicky about scoping

#8387: View patterns + pattern bindings: finnicky about scoping ----------------------------+---------------------------------------------- Reporter: | Owner: tinctorius | Status: new Type: bug | Milestone: Priority: normal | Version: 7.6.3 Component: Compiler | Operating System: Unknown/Multiple Keywords: | Type of failure: GHC rejects valid program Architecture: | Test Case: Unknown/Multiple | Blocking: Difficulty: Unknown | Blocked By: | Related Tickets: | ----------------------------+---------------------------------------------- Assume `{-# LANGUAGE ViewPatterns #-}`. This works: {{{ (id -> ()) = () }}} This also works: {{{ di :: a -> a di = \x -> x where (di -> ()) = () }}} But none of the following work: {{{ (di -> ()) = () -- Not in scope: di di :: a -> a di = \x -> x }}} {{{ di :: a -> a di = \x -> x (di -> ()) = () -- Not in scope: di }}} {{{ (di -> ()) = () -- Not in scope: di where di :: a -> a di = \x -> x }}} This looks like a bug to me. Is it? And is this in any way related to #4061? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8387 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8387: View patterns + pattern bindings: finnicky about scoping ----------------------------------------------+---------------------------- Reporter: tinctorius | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects valid program | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Comment (by rwbarton): It is related to #4061, and I think that GHC is correctly implementing the scoping rule in the user's guide:
In mutually recursive bindings, such as let, where, or the top level, view patterns in one declaration may not mention variables bound by other declarations. That is, each declaration must be self-contained.
That doesn't mean the rule is written in stone. I wonder whether it could be:
In mutually recursive bindings ... view patterns in one declaration may not mention variables bound by other ''view patterns''.
---- As a workaround, you can use the Template Haskell hack I just posted on #4061 to get your second example to compile. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8387#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8387: View patterns + pattern bindings: finnicky about scoping ----------------------------------------------+---------------------------- Reporter: tinctorius | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects valid program | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Comment (by tinctorius): But they are not mutually recursive. The view pattern binding depends on the function binding, but not the other way around. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8387#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8387: View patterns + pattern bindings: finnicky about scoping ----------------------------------------------+---------------------------- Reporter: tinctorius | Owner: Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects valid program | Unknown/Multiple Test Case: | Difficulty: Unknown Blocking: | Blocked By: | Related Tickets: ----------------------------------------------+---------------------------- Comment (by simonpj): I remember this as being very fiddly, so I opted for a simple solution. It's hard to motivate fancy footwork in the compiler without having some pretty compelling use-cases that motivate it. If you (and preferably a bunch of others) have really run up against this restriction in a big way, please do describe the situation, and why the workarounds are unsatisfactory. Simon -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8387#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#8387: View patterns + pattern bindings: finnicky about scoping -------------------------------------+------------------------------------- Reporter: tinctorius | Owner: Type: bug | Status: closed Priority: normal | Milestone: Component: Compiler | Version: 7.6.3 Resolution: wontfix | Keywords: Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #4061 | Differential Revisions: -------------------------------------+------------------------------------- Changes (by thomie): * status: new => closed * resolution: => wontfix * related: => #4061 -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8387#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC