Opened 6 years ago

Closed 4 years ago

#8403 closed bug (wontfix)

Pretty-printing of long types

Reported by: monoidal Owned by:
Priority: lowest Milestone:
Component: Compiler Version: 7.6.3
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Other Test Case:
Blocked By: Blocking:
Related Tickets: #9428 Differential Rev(s):
Wiki Page:

Description

Low priority, but this ghci output could be more packed.

λ> :t (,,,,,,,,,,,,,,,,,,,,,,,)
(,,,,,,,,,,,,,,,,,,,,,,,)
  :: a
     -> b
     -> c
     -> d
     -> e
     -> f
     -> g
     -> h
     -> i
     -> j
     -> k
     -> l
     -> m
     -> n
     -> o
     -> p
     -> q
     -> r
     -> s
     -> t
     -> u
     -> v
     -> w
     -> x
     -> (a,
         b,
         c,
         d,
         e,
         f,
         g,
         h,
         i,
         j,
         k,
         l,
         m,
         n,
         o,
         p,
         q,
         r,
         s,
         t,
         u,
         v,
         w,
         x)

Change History (6)

comment:1 Changed 5 years ago by thomie

Thank you for the report. #9428 looks like another instance of this bug, but then for error messages.

comment:2 Changed 5 years ago by thomie

Keywords: newcomer added

Might not be easy, but I think a fix is to be found in this single file: compiler/utils/Pretty.hs.

For historical reasons, there's also a copy in libraries/pretty. See https://github.com/haskell/pretty/issues/1.

comment:3 Changed 5 years ago by phadej

With the test program:

import Text.PrettyPrint

-- mocking how compiler/types/TypeRep.hs would print the type
pairUntil :: Char -> Doc
pairUntil c = pprArrowChain (varDocs ++ [resultPair])
  where varDocs = map char ['a'..c]
        resultPair = parens (sep (punctuate comma varDocs))

arrow :: Doc
arrow = text "->"

pprArrowChain :: [Doc] -> Doc
-- pprArrowChain [a,b,c]  generates   a -> b -> c
pprArrowChain  []         = empty
pprArrowChain (arg:args) = sep [arg, sep (map (arrow <+>) args)]
λ> Test.pairUntil 'd'
a -> b -> c -> d -> (a, b, c, d)
λ> Test.pairUntil 'k'
a
-> b
-> c
-> d
-> e
-> f
-> g
-> h
-> i
-> j
-> k
-> (a, b, c, d, e, f, g, h, i, j, k)

I have no good ideas how to define "more packed", yet so output is still understandable. E.g. will this "less area" method work for all types:

a -> b -> c -> d -> e -> f -> g -> h -> i -> j
  -> k -> l -> m -> n -> o -> p -> q -> r -> s
  -> t -> u -> v -> w -> x
  -> (a, b, c, d, e, f, g, h, i, j, k, l,
      m, n, o, p, q, r, s, t, u, v, w, x)

My gut feelings that the layout algorithm won't be linear anymore, don't know if that is the problem though.

comment:4 Changed 5 years ago by joehillen

Just to be clear.

What exactly is the problem with the current formatting? It seems to make perfect sense and is reasonable to break at every '->' or ','. To me, the current behavior is more readable than the proposed alternative. Even if it does take up more vertical space.

comment:5 Changed 5 years ago by thomie

Keywords: newcomer removed

Yeah, maybe just leave it the way it is.

comment:6 Changed 4 years ago by thomie

Resolution: wontfix
Status: newclosed

See comment:4.

Please reopen if you really want this.

Note: See TracTickets for help on using tickets.