Opened 18 months ago

Last modified 15 months ago

#14995 new bug

QuantifiedConstraints: Incorrect pretty printing

Reported by: Iceland_jack Owned by:
Priority: low Milestone:
Component: GHCi Version: 8.2.2
Keywords: QuantifiedConstraints Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Poor/confusing error message Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description (last modified by Iceland_jack)

This code from OutsideIn(X) compiles

{-# 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> 

Change History (4)

comment:1 Changed 18 months ago by Iceland_jack

Description: modified (diff)

comment:2 Changed 18 months ago 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.

comment:3 Changed 16 months ago by RyanGlScott

Keywords: wipT2893 removed

comment:4 Changed 15 months ago by mgsloan

Priority: normallow
Note: See TracTickets for help on using tickets.