Discuss `Show` instance for `Annotation tag`
Clarification and motivation
There's an unwritten expectation that the output of show
should be a string you can copy-paste back into the editor.
That is what stock instances do, and what haskell devs usually expect to see:
Derived instances of Show have the following properties, which are compatible with derived instances of Read:
The result of show is a syntactically correct Haskell expression containing only constants (...)
The ability to be able to show a value and copy-paste it into the editor is extremely useful while debugging.
However, the Show
instance for Annotation tag
doesn't do this. It pretty-prints the annotation:
λ> [fieldAnnQ|a|]
%a
Furthermore, this can lead to confusing scenarios. For example, the Show
instance for Notes t
outputs a "syntactically correct Haskell expression" with pretty-printed (syntactically incorrect) annotations in the middle:
λ> NTPair @'T.TInt @'T.TInt noAnn [fieldAnnQ|a|] noAnn [varAnnQ|b|] noAnn starNotes starNotes
NTPair %a @b (NTInt) (NTInt)
Notice how NTInt
's field and 3 of NTPair
's fields are completely missing from the output.
For those reasons, I think we should just use a stock-derived instance for Annotation tag
.
On the other hand, the stock derived instance will not show the phantom type tag
, which can also be useful.
So perhaps printing one of these would be a fair compromise:
- Print a type application:
UnsafeAnnotation @tag "ann"
- Print a quasiquote:
[fieldAnnQ|ann|]
They're both copy-pastable syntactically correct Haskell expressions.
Thoughts?
Also, slightly related topic: The output of pretty
for Notes t
instance is not very... pretty?
λ> pretty $ NTPair @'T.TInt @'T.TInt noAnn [fieldAnnQ|a|] noAnn [varAnnQ|b|] noAnn starNotes starNotes
NTPair %a @b (NTInt) (NTInt)
I suggest changing it to build = build . mkUType
, which would print:
pair (int %a @b) int
Acceptance criteria
- We've decided what to do about the
Show
instance forAnnotation tag