agrafix / superrecord

Haskell: Supercharged anonymous records
BSD 3-Clause "New" or "Revised" License
83 stars 16 forks source link

Change Show-instances to use `"#field := val"` #37

Open Profpatsch opened 2 years ago

Profpatsch commented 2 years ago

The previous show instance would add another layer of quoting for each nesting:

ghci> show (rcons (#foo := "bar") rnil)
"[(\"foo\",\"\\\"bar\\\"\")]"

Instead, what we want is to display a nicely readable variant of the record, using the infix field syntax for both label/value pairs and full records:

ghci> show (rcons (#hi := (rcons (#lea := "hi") rnil)) (rcons (#foo := "bar") rnil ))
"[#foo := \"bar\",#hi := [(#lea := \"hi\")]]"

ghci> show (#hi := "lea")
"#hi := \"lea\""

That’s better!

Note that we can’t have a roundtripping Read instance anyway, so we might as well have Show be readable.

Fixes https://github.com/agrafix/superrecord/issues/36

This includes the changes from #35

Profpatsch commented 2 years ago

Note that

ghci> show (FldProxy @"ab cd ef" := "lea")
"#ab cd ef := \"lea\""

So in that case we might want to have a special case? Thoughts?