Opened 5 years ago

Closed 5 years ago

#9658 closed bug (fixed)

Prettyprint constraints in type signatures can omit necessary parentheses

Reported by: Blaisorblade Owned by:
Priority: low Milestone: 7.8.4
Component: GHCi Version: 7.8.3
Keywords: Cc: hvr
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case: ghci/scripts/T9658
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:


GHCi prettyprinting can omit parentheses around constraints, even when they are necessary for the signature to be syntactically valid. This breaks the workflow where one uses type inference to generate type annotations to add to the program. Admittedly, this is nitpicking, but it'd be nice to fix.

The example I'm running into is the following (in the context of

num = inj . Num

> :t num
num :: NUM :<: sup => Int -> sup (Full Int)

Adding the type annotation in gives:

src/Syntactic.hs:115:20: parse error on input `=>'

To fix the parse error, I need to add parentheses around the constraint:

num :: (NUM :<: sup) => Int -> sup (Full Int)

(Here this happens to be the wrong type signature, but that's orthogonal).

I imagine that's just because the constraint uses an operator (probably only possible with TypeOperators).

This happens whether I explicitly supply the signature or not, and it also happens on GHC 7.6.3.

Misc: I selected milestone, difficulty, priority because it's possible and because fixing this sounds easy; sorry if I shouldn't have. I also didn't check whether this affects HEAD.

Change History (4)

comment:1 Changed 5 years ago by Simon Peyton Jones <simonpj@…>

In 48089ccf4f1f239b3268b2cb52b8aa0f7356485b/ghc:

Use correct precedence when printing contexts with class operators

Fixes Trac #9658

comment:2 Changed 5 years ago by simonpj

Resolution: fixed
Status: newclosed
Test Case: ghci/scripts/T9658

Fixed, thanks


comment:3 Changed 5 years ago by thoughtpolice

Status: closedmerge

comment:4 Changed 5 years ago by thoughtpolice

Status: mergeclosed

Merged to ghc-7.8.

Note: See TracTickets for help on using tickets.