cdepillabout / pretty-simple

pretty-printer for Haskell data types that have a Show instance
https://hackage.haskell.org/package/pretty-simple
BSD 3-Clause "New" or "Revised" License
243 stars 29 forks source link

Wrong indentation in pretty printer #56

Open sureyeaah opened 4 years ago

sureyeaah commented 4 years ago

Reproduce:

pPrint( ((1, 2), 3, (4)) )

Current behavior

( 
    ( 1
    , 2
    ) 
, 3
, ( 4 )
) 

Expected behavior: First tuple should be aligned with the rest of the elements.

( 
  ( 1
  , 2
  ) 
, 3
, ( 4 )
) 

Is the current behavior intentional?

cdepillabout commented 4 years ago

@sureyeaah I don't remember if this behavior is intentional or not, but I agree that it doesn't make any sense.

If you want to fix this when working on https://github.com/cdepillabout/pretty-simple/issues/25, please feel free.

georgefst commented 4 years ago

The 'expected behaviour' here is actually precisely what you get with pPrintStringOpt (defaultOutputOptionsDarkBg {outputOptionsIndentAmount = 2}).

As for how leading commas and four space indentation should interact, I've been pondering that while working on Fourmolu, where the status quo is close to your expected output, but that actually leads to a weird mix of two- and four-space indentation that I'm not happy with. So the current pretty-simple output is close to what I'm intending to implement there... What don't you like about it?

sureyeaah commented 4 years ago

Well what i don't like about the current behaviour as described in the issue is that it makes no sense. Why are the first element's paranthesis indented with 4 spaces while third with 2 - doesn't seem right.

If the expected behaviour is what pretty simple produces then this is resolved.

georgefst commented 4 years ago

Why are the first element's parantheses indented with 4 spaces while third with 2 - doesn't seem right.

Because in a sense the third subexpression isn't really indented at all. Regardless of the indentation step, there's just the one space after the comma.

You could have this, but I think it looks weird:

( 
    ( 1
    , 2
    ) 
,     3
,   ( 4 )
) 

I think if you care about those lining up, you have to just use 2 space indentation. I've never seen a good solution with 4.