[GHC] #15893: View Patterns affect typechecking in an unpredictable manner

#15893: View Patterns affect typechecking in an unpredictable manner -------------------------------------+------------------------------------- Reporter: theindigamer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: ⊥ Component: Compiler | Version: 8.4.3 Keywords: ViewPatterns | Operating System: Unknown/Multiple Architecture: | Type of failure: GHC rejects Unknown/Multiple | valid program Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- Copying the text from my [https://stackoverflow.com/questions/53294823 /viewpatterns-affects-typechecking-in-an-unpredictable-manner StackOverflow question]. {{{ {-# LANGUAGE ViewPatterns #-} import Data.Text (Text) import qualified Data.Text as T import qualified Data.Vector.Unboxed as UV import qualified Data.Vector.Generic as V bar :: Int -> UV.Vector Char -> (Text, Text) bar i v = (t_pre, t_post) where f = T.pack . V.toList (f -> t_pre, f -> t_post) = V.splitAt i v }}} This gives an unexpected type error (tested with GHC 8.4.3), concerning ambiguous type variables and `f` being out of scope. {{{ • Ambiguous type variable ‘v0’ arising from a use of ‘V.toList’ prevents the constraint ‘(V.Vector v0 Char)’ from being solved. Relevant bindings include f :: v0 Char -> Text (bound at Weird.hs:11:5) Probable fix: use a type annotation to specify what ‘v0’ should be. These potential instances exist: instance V.Vector UV.Vector Char -- Defined in ‘Data.Vector.Unboxed.Base’ ...plus one instance involving out-of-scope types instance primitive-0.6.3.0:Data.Primitive.Types.Prim a => V.Vector Data.Vector.Primitive.Vector a -- Defined in ‘Data.Vector.Primitive’ • In the second argument of ‘(.)’, namely ‘V.toList’ In the expression: T.pack . V.toList In an equation for ‘f’: f = T.pack . V.toList | 11 | f = T.pack . V.toList | ^^^^^^^^ Weird.hs:13:6: error: Variable not in scope: f :: UV.Vector Char -> t | 13 | (f -> t_pre, f -> t_post) = V.splitAt i v | ^ Weird.hs:13:18: error: Variable not in scope: f :: UV.Vector Char -> t1 | 13 | (f -> t_pre, f -> t_post) = V.splitAt i v | ^ }}} Some of the other answers on SO have done some digging (e.g. enabling FlexibleContexts / NoMonomorphismRestriction doesn't solve the issue). I haven't yet figured out how to minimize the example further to remove the dependency on Vector... Is this a compiler bug or a documentation bug? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15893 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15893: View Patterns affect typechecking in an unpredictable manner -------------------------------------+------------------------------------- Reporter: theindigamer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: ⊥ Component: Compiler | Version: 8.4.3 Resolution: | Keywords: ViewPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): Wow. Here's an example with no dependencies {{{ bar :: Int -> (Int,Int) bar i = (t_pre, t_post) where f :: Int -> Int f j = j (f -> t_pre, f -> t_post) = (i+1, i-1) }}} We get {{{ T15893.hs:10:6: error: * Variable not in scope: f :: Int -> t * Perhaps you meant `f' (line 9) | 10 | (f -> t_pre, f -> t_post) = (i+1, i-1) | ^ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15893#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15893: View Patterns affect typechecking in an unpredictable manner -------------------------------------+------------------------------------- Reporter: theindigamer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: ⊥ Component: Compiler | Version: 8.4.3 Resolution: | Keywords: ViewPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #14293 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * related: => #14293 Comment: Isn't this just a duplicate of #14293? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15893#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15893: View Patterns affect typechecking in an unpredictable manner -------------------------------------+------------------------------------- Reporter: theindigamer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: ⊥ Component: Compiler | Version: 8.4.3 Resolution: | Keywords: ViewPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #14293 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by theindigamer): Huh, looks like I didn't use the query tool correctly. I did use "ViewPatterns" as a keyword but it gave me no results when I searched. :( -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15893#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15893: View Patterns affect typechecking in an unpredictable manner -------------------------------------+------------------------------------- Reporter: theindigamer | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: ⊥ Component: Compiler | Version: 8.4.3 Resolution: | Keywords: ViewPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #14293 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by RyanGlScott): Don't worry, that's not your fault—#14923 wasn't properly tagged with the ViewPatterns keyword, so it was impossible to discover originally :) (I've since amended it with that keyword.) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15893#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15893: View Patterns affect typechecking in an unpredictable manner -------------------------------------+------------------------------------- Reporter: theindigamer | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: ⊥ Component: Compiler | Version: 8.4.3 Resolution: duplicate | Keywords: ViewPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #14293 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * status: new => closed * resolution: => duplicate -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15893#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15893: View Patterns affect typechecking in an unpredictable manner -------------------------------------+------------------------------------- Reporter: theindigamer | Owner: (none) Type: bug | Status: closed Priority: normal | Milestone: ⊥ Component: Compiler | Version: 8.4.3 Resolution: duplicate | Keywords: ViewPatterns Operating System: Unknown/Multiple | Architecture: Type of failure: GHC rejects | Unknown/Multiple valid program | Test Case: Blocked By: | Blocking: Related Tickets: #14293 | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): As usual, Ryan, you are spot on. I'd totally forgotten about #14293. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15893#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC