#14796 closed bug (fixed)

Pretty Printing: GHC doesn't parenthesise (() :: Constraint)

Reported by: Iceland_jack Owned by:
Priority: normal Milestone: 8.6.1
Component: Compiler Version: 8.5
Keywords: TypeApplications Cc: alanz
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case: ghci/scripts/T14796
Blocked By: Blocking:
Related Tickets: #14808 Differential Rev(s): Phab:D4408
Wiki Page:

Description (last modified by Iceland_jack)

From Ryan's How to derive Generic for (some) GADTs using QuantifiedConstraints:

data ECC ctx f a where
  ECC :: ctx => f a -> ECC ctx f a

When instantiating the Constraint using -XTypeApplications with the empty constraint, GHC doesn't add parentheses (it should look like ... -> ECC (() :: Constraint) [] ())

$ ~/code/qc-ghc/inplace/bin/ghc-stage2 --interactive -ignore-dot-ghci
GHCi, version 8.5.20180128: http://www.haskell.org/ghc/  :? for help
Prelude> :set -XGADTs -XConstraintKinds -XTypeApplications 
Prelude> data ECC ctx f a where ECC :: ctx => f a -> ECC ctx f a
Prelude> :t ECC @[] @() @()
ECC @[] @() @() :: [()] -> ECC () :: Constraint [] ()

Doesn't seem to happen in other cases:

Prelude> :t ECC @[] @() @((), ())
ECC @[] @() @((), ())
  :: [()] -> ECC (() :: Constraint, () :: Constraint) [] ()

Prelude> :t ECC @[] @() @(Eq Int)
ECC @[] @() @(Eq Int) :: [()] -> ECC (Eq Int) [] ()

Change History (8)

comment:1 Changed 20 months ago by Iceland_jack

Description: modified (diff)

comment:2 Changed 20 months ago by Iceland_jack

Ryan had trouble reproducing it so here it is for 8.2.1

$ ghci-8.2.1 -ignore-dot-ghci
GHCi, version 8.2.1: http://www.haskell.org/ghc/  :? for help
Prelude> :set -XGADTs -XConstraintKinds -XTypeApplications
Prelude> data ECC ctx f a where ECC :: ctx => f a -> ECC ctx f a
Prelude> :t ECC @() @[] @()
ECC @() @[] @() :: [()] -> ECC () :: Constraint [] ()

comment:3 Changed 20 months ago by Iceland_jack

Cc: Calanz added; TypeApplications removed
Description: modified (diff)
Keywords: TypeApplications added
Summary: Pretty-printer bugPretty Printing: GHC doesn't parenthesise (() :: Constraint)

comment:4 Changed 20 months ago by RyanGlScott

Cc: alanz added; Calanz removed

comment:5 Changed 20 months ago by Iceland_jack

Description: modified (diff)

comment:6 Changed 20 months ago by RyanGlScott

Differential Rev(s): Phab:D4408
Status: newpatch

Egads, there's an even more serious bug lurking here—the fact that you have to visibly apply the arguments to ECC in completely different orders on GHC 8.2.2/8.4.1 and HEAD! I've opened #14808 for this.

In the meantime, I've opened Phab:D4408 for this bug, which is straightforward to fix.

comment:7 Changed 19 months ago by Ryan Scott <ryan.gl.scott@…>

In 99c556d2/ghc:

Parenthesize (() :: Constraint) in argument position

Summary:
A simple oversight in the pretty-printer lead to a special
case for `() :: Constraint` not being parenthesized correctly when
used in an argument position. Easily fixed with a `maybeParen`.

Test Plan: make test TEST=T14796

Reviewers: alanz, goldfire, bgamari, simonpj

Reviewed By: bgamari, simonpj

Subscribers: simonpj, rwbarton, thomie, carter

GHC Trac Issues: #14796

Differential Revision: https://phabricator.haskell.org/D4408

comment:8 Changed 19 months ago by RyanGlScott

Milestone: 8.6.1
Resolution: fixed
Status: patchclosed
Test Case: ghci/scripts/T14796
Note: See TracTickets for help on using tickets.