[GHC] #15661: Nullary constraint in GHCi breaks `:t` command

#15661: Nullary constraint in GHCi breaks `:t` command -------------------------------------+------------------------------------- Reporter: taktoa | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: GHCi | 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: -------------------------------------+------------------------------------- If you create a value whose type has a nullary constraint (i.e.: a constraint that does not reference any of the type variables in scope) and then try to run `:t` on it, GHCi attempts to run instance resolution and fails before printing the type. Expected output: {{{ GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help Prelude> :set -XFlexibleContexts Prelude> data Foo = Foo Prelude> let x :: (Show Foo) => () ; x = () Prelude> :t x x :: Show Foo => () }}} Actual output: {{{ GHCi, version 8.4.3: http://www.haskell.org/ghc/ :? for help Prelude> :set -XFlexibleContexts Prelude> data Foo = Foo Prelude> let x :: (Show Foo) => () ; x = () Prelude> :t x <interactive>:1:1: error: No instance for (Show Foo) arising from a use of ‘x’ }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15661 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15661: Nullary constraint in GHCi breaks `:t` command -------------------------------------+------------------------------------- Reporter: taktoa | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: GHCi | 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 simonpj): This behaviour is just what you'd expect. Remember: `:type <expression>` takes an ''arbitrary expression'' (not just a variable), finds its most general type, and shows that type. Here the expression happens to be just a single variable `x`. Fine, so we instantiate `x`, which gives rise to a "wanted" `(Show Foo)`. Then we attempt to solve and generalise, but `(Show Foo)` is not soluble. Hence the error. If you just want to see `x's` type, use `:info`, thus {{{ ghci> :info x x :: Show Foo => () -- Defined at <interactive>:3:26 }}} I think everything seems fine here. But it clearly wasn't what you expected. Does my explanation help? -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15661#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#15661: Nullary constraint in GHCi breaks `:t` command -------------------------------------+------------------------------------- Reporter: taktoa | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: 8.6.1 Component: GHCi | 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 RyanGlScott): Alternatively, you can use `:type +v x`, which finds the type signature without solving and generalizing. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/15661#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC