[GHC] #14995: QuantifiedConstraints: Incorrect pretty printing

#14995: QuantifiedConstraints: Incorrect pretty printing -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.2.2 Keywords: | Operating System: Unknown/Multiple QuantifiedConstraints, wipT2893 | Architecture: | Type of failure: Poor/confusing Unknown/Multiple | error message Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- This code from [https://www.microsoft.com/en-us/research/wp- content/uploads/2016/02/jfp-outsidein.pdf OutsideIn(X)] compiles {{{#!hs {-# Language FlexibleInstances, MultiParamTypeClasses, GADTs, QuantifiedConstraints #-} class C a class B a b where op :: a -> b instance C a => B a [a] where op = undefined data R a where MkR :: C a => a -> R a k :: (C a => B a b) => R a -> b k (MkR x) = op x }}} but pretty-printing `k` prints `B a b => ..` instead of `(C a => B a b) => ..` {{{ $ ghci -ignore-dot-ghci Test.hs GHCi, version 8.5.20180128: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( hs/228-bug.hs, interpreted ) Ok, one module loaded. *Main> :t k k :: B a b => R a -> b *Main> }}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14995 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14995: QuantifiedConstraints: Incorrect pretty printing -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.2.2 Resolution: | Keywords: | QuantifiedConstraints, wipT2893 Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Description changed by Iceland_jack: Old description:
This code from [https://www.microsoft.com/en-us/research/wp- content/uploads/2016/02/jfp-outsidein.pdf OutsideIn(X)] compiles
{{{#!hs {-# Language FlexibleInstances, MultiParamTypeClasses, GADTs, QuantifiedConstraints #-}
class C a class B a b where op :: a -> b instance C a => B a [a] where op = undefined
data R a where MkR :: C a => a -> R a
k :: (C a => B a b) => R a -> b k (MkR x) = op x }}}
but pretty-printing `k` prints `B a b => ..` instead of `(C a => B a b) => ..`
{{{ $ ghci -ignore-dot-ghci Test.hs GHCi, version 8.5.20180128: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( hs/228-bug.hs, interpreted ) Ok, one module loaded. *Main> :t k k :: B a b => R a -> b *Main> }}}
New description: This code from [https://www.microsoft.com/en-us/research/wp- content/uploads/2016/02/jfp-outsidein.pdf OutsideIn(X)] compiles {{{#!hs {-# Language FlexibleInstances, MultiParamTypeClasses, GADTs, QuantifiedConstraints #-} class C a class B a b where op :: a -> b instance C a => B a [a] where op = undefined data R a where MkR :: C a => a -> R a k :: (C a => B a b) => R a -> b k (MkR x) = op x }}} but pretty-printing `k` prints `B a b => ..` instead of `(C a => B a b) => ..` {{{ $ ghci -ignore-dot-ghci hs/228-bug.hs GHCi, version 8.5.20180128: http://www.haskell.org/ghc/ :? for help [1 of 1] Compiling Main ( hs/228-bug.hs, interpreted ) Ok, one module loaded. *Main> :t k k :: B a b => R a -> b *Main> }}} -- -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14995#comment:1 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14995: QuantifiedConstraints: Incorrect pretty printing -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.2.2 Resolution: | Keywords: | QuantifiedConstraints, wipT2893 Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Comment (by simonpj): This is like #14897. It'l be fine if you say `:info k`. But with `:t k` you are asking GHC to infer the type of the expression `k`. So it instantiates `k` to get the constraint {{{ [W] ((C a1 => B a1 b1)) -- A quantified constraint }}} As usual `a1` and `b1` are unification variables. To solve a quantified constraint we create an implication constraint {{{ forall {}. C a1 => [W] B a1 b1 }}} Now we are stuck, so we try to generalise. GHC tries to find a simple constraint to generalise over, and `B a1 b1` does the job. GHC ''never'' infers a quantified constraint. So `:t` will never display a quantified constraint. I don't know whether others trip over this `:type` vs `:info` distinction, but you certainly do! Maybe `:type` should work only on identifiers, and be identical to `:info`. We could have something else for arbitrary expressions. Or maybe `:type` should behave non-uniformly for identifiers. Opinions welcome. But as it stands it's by-design. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14995#comment:2 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14995: QuantifiedConstraints: Incorrect pretty printing -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: GHCi | Version: 8.2.2 Resolution: | Keywords: | QuantifiedConstraints Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by RyanGlScott): * keywords: QuantifiedConstraints, wipT2893 => QuantifiedConstraints -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14995#comment:3 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler

#14995: QuantifiedConstraints: Incorrect pretty printing -------------------------------------+------------------------------------- Reporter: Iceland_jack | Owner: (none) Type: bug | Status: new Priority: low | Milestone: Component: GHCi | Version: 8.2.2 Resolution: | Keywords: | QuantifiedConstraints Operating System: Unknown/Multiple | Architecture: Type of failure: Poor/confusing | Unknown/Multiple error message | Test Case: Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Wiki Page: | -------------------------------------+------------------------------------- Changes (by mgsloan): * priority: normal => low -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14995#comment:4 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler
participants (1)
-
GHC