yav / pretty-show

Tools for working with derived Show instances in Haskell.
MIT License
57 stars 15 forks source link

Cannot pretty-show "special" Show instances #2

Closed nh2 closed 12 years ago

nh2 commented 12 years ago

I currently have some problems pretty-showing non-standard things like dates:

import Data.Time.Clock
now <- getCurrentTime
putStrLn $ ppShow [now,now]

yields

[2012-01-19 02:58:25.978235 UTC,2012-01-19 02:58:25.978235 UTC]

while I would expect

[2012-01-19 02:58:25.978235 UTC
,2012-01-19 02:58:25.978235 UTC
]

pretty-show doesn't know how to parse this, which on its own is fine.

The problem is that as soon as one such data type is used in whatever data structure, the whole structure cannot be pretty-printed anymore and is ppShow'ed on one line (as above, though it is a list with 2 elements which ppShow usually formats on multiple lines).

It would be great to have pretty-show ignore all such strange Show instances (like dates) which it doesn't understand and render them as untouched strings while pretty-formatting the surrounding structures.

Probably this needs moving away from using the Haskell lexer as much as it does now to more work being done on the type level, although lexing would still be necessary for some parts (e.g. to nicely format type constructors).

nh2 commented 12 years ago

Huh, double-post?! See #1.

yav commented 12 years ago

Hi there, I just added some support for various times to pp-show. Try it out, it is version 1.2 on hackage. (or you can just checkout the repo)