[GHC] #15603: ref6 example from StaticPointers documentation doesn't type check

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- The [https://downloads.haskell.org/~ghc/8.4.3/docs/html/users_guide/glasgow_exts.... #extension-StaticPointers documentation] for `StaticPointers` contains the following example. {{{ ref6 y = let x = 1 in static x }}} but this doesn't get accepted by the type checker. {{{ sp.hs:27:23: error: • ‘x’ is used in a static form but it is not closed because it has a non-closed type because it contains the type variables: ‘p_a7KP’ • In the expression: static x In the expression: let x = 1 in static x In an equation for ‘ref6’: ref6 y = let x = 1 in static x | 27 | ref6 y = let x = 1 in static x | ^^^^^^^ }}} I tested on 8.6.1, 8.4.3, 8.2.2, 8.02, 7.10.3 and all fail. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by monoidal): This is due to Num. How about changing to `ref6 y = let x = 'a' in static x`? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): That works. I'm unsure what the `y` is doing in there as well tbh, it doesn't seem to add anything. Adding a top-level type signature to this example doesn't fix the problem but specifying `(1 :: Int)` also fixes it. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by monoidal): Yes, we can remove `y`. Also `ref1` is wrong in the same way. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): You might think so but `ref1` type checks without any type signatures. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by monoidal): What do you mean? If I create a file {{{ {-# LANGUAGE StaticPointers #-} ref1 = static 1 }}} then GHCs 8.0-8.4 give an error about missing `Typeable t0` instance (or if monomorphism restriction is disabled, about missing `Num a`) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:5 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): Ah, I had another call to `ref1` in my program which was fixing the type. You're right. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:6 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by mpickering): The `static show` example also doesn't produce an error exactly like the implied one. {{{ sp.hs:25:7: error: • No instance for (Typeable a0) arising from a static form • In the expression: static show In an equation for ‘foo’: foo = static show | 25 | foo = static show | ^^^^^^^^^^^ sp.hs:25:14: error: • Ambiguous type variable ‘a0’ arising from a use of ‘show’ prevents the constraint ‘(Show a0)’ from being solved. Relevant bindings include foo :: t0 (a0 -> String) (bound at sp.hs:25:1) Probable fix: use a type annotation to specify what ‘a0’ should be. These potential instances exist: instance Show (ST s a) -- Defined in ‘GHC.ST’ instance Show StaticPtrInfo -- Defined in ‘GHC.StaticPtr’ instance Show Ordering -- Defined in ‘GHC.Show’ ...plus 25 others ...plus 12 instances involving out-of-scope types (use -fprint-potential-instances to see them all) • In the body of a static form: show In the expression: static show In an equation for ‘foo’: foo = static show | 25 | foo = static show | ^^^^ }}} Then adding a type signature leads to the confusing error: {{{ foo :: (Typeable a, Show a) => StaticPtr (a -> String) foo = static show }}} {{{ sp.hs:26:14: error: • No instance for (Show a) arising from a use of ‘show’ • In the body of a static form: show In the expression: static show In an equation for ‘foo’: foo = static show | 26 | foo = static show | }}} The user guide should discuss why these errors happen to help understanding. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:7 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: | StaticPointers Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by simonpj): * keywords: => StaticPointers -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:8 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15603: ref6 example from StaticPointers documentation doesn't type check -------------------------------------+------------------------------------- Reporter: mpickering | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: Compiler | Version: 8.4.3 Resolution: | Keywords: | StaticPointers, newcomer Operating System: Unknown/Multiple | Architecture: | Unknown/Multiple Type of failure: None/Unknown | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mpickering): * keywords: StaticPointers => StaticPointers, newcomer -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15603#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC