`Show` instance for `Json`
menelaos opened this issue ยท 5 comments
Was it a deliberate decision to remove the Show instance for Json in 83dd71f? I stumbled upon this due to some broken tests that were using (===) from purescript-strongcheck, which relies on Show.
It was deliberate, yeah. It breaks the idea of Show printing something equivalent to the PureScript code that constructs it.
That's what I feared ;-) Do you have an example of where the Show instance might pose a problem?
@menelaos I don't believe it's necessarily that Show causes a problem in the code produced, but that the point of the Show type class is for debugging and printing out a PureScript representation of data and types rather than for formatting strings.
If you want to 'print' JSON values use the stringify function, which is further described in the MDN documentation (if you need it :))
Let me try to make an argument for bringing back the Show instance for Json.
I (and I imagine most people?) mainly use Show for debugging. In order to show a Json, you have to call stringify. While this isn't a huge problem, it is a small papercut that I get again and again when working with PureScript. Adding a Show Json instance would remove this small papercut for me.
@garyb and @thomashoneyman say above:
It breaks the idea of Show printing something equivalent to the PureScript code that constructs it.
the point of the Show type class is for debugging and printing out a PureScript representation of data and types rather than for formatting strings.
However, the docs on Show say the following
While not required, it is recommended that for any expression
x, theStringshow xbe executable PureScript code which evaluates to the same value as the expressionx.
I think the "while not required" is important. While it would be great if Show Json could produce valid PureScript code, Show Json is still pretty helpful for debugging if it doesn't produce valid PureScript code.
Having Show produce valid code is pretty important in the Haskell ecosystem because of the prevalence of Read. And non-conforming instances are one of the reasons for libraries like pretty-simple. However, there is no Read in PureScript, so I don't know how strong of a reason this is for PureScript.
I imagine some people like to Show data types, and then copy and paste them back to the repl to play around with them. It is unfortunate that you can't do this with Show Json, but removing the instance isn't helping the situation. It wouldn't be possible to copy-and-paste the output JSON whether you use Show Json, or just stringify.
Given this, I think having the Show Json instance slightly reduces the small repeated mental overhead of having to import stringify.