hustle icon indicating copy to clipboard operation
hustle copied to clipboard

Show typeclass should not be used to pretty-print a data structure

Open tchoutri opened this issue 4 months ago • 1 comments

While debugging #6 I was puzzled why parsing from GHCi would not give me the underlying data structure but a pretty-printed representation, until I found that Document's Show instance (defined in Formatter.hs) was used to do pretty-printing.

If we are comparing to Rust, Show is Haskell's Debug trait and thus must not be used for pretty-printing data structure.

The Pretty typeclass is already used in the project and does its job well. Show must be left derived so that we can inspect the content of the data structures when debugging the code.

I can remove the pretty-printed Show instance as part of my PR to fix #6.

tchoutri avatar Aug 07 '25 18:08 tchoutri

Reverting to the derived Show instance has allowed to me to see that this is not a formatting problem but a parsing issue, because "0" gets parsed as a Scientific number:

nodeArgs = [Value {valueAnn = Nothing, valueExp = SciValue 0.0}]

tchoutri avatar Aug 07 '25 18:08 tchoutri