Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Rec produces nested escaping #36

Open
Profpatsch opened this issue Nov 10, 2022 · 0 comments · May be fixed by #37
Open

Show Rec produces nested escaping #36

Profpatsch opened this issue Nov 10, 2022 · 0 comments · May be fixed by #37

Comments

@Profpatsch
Copy link

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

I think there is an extra layer of show there that shouldn’t be.

Some people say Show should roundtrip with Read, but I don’t see how it’s possible with Superrecord anyway.

Profpatsch added a commit to possehl-analytics/superrecord that referenced this issue Nov 10, 2022
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 agrafix#36
@Profpatsch Profpatsch linked a pull request Nov 10, 2022 that will close this issue
Profpatsch added a commit to possehl-analytics/superrecord that referenced this issue Nov 10, 2022
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 agrafix#36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant