-
Notifications
You must be signed in to change notification settings - Fork 17
Add Show instances for the Rep types #11
Add Show instances for the Rep types #11
Conversation
src/Data/Generic/Rep.purs
Outdated
show (Product a b) = "(Product " <> show a <> " " <> show b <> ")" | ||
|
||
instance showConstructor :: (IsSymbol name, Show a) => Show (Constructor name a) where | ||
show (Constructor a) = "(Constructor \"" <> reflectSymbol (SProxy :: SProxy name) <> "\" " <> show a <> ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's use show
on the string here, instead of wrapping in quotes, since it might need escaping.
src/Data/Generic/Rep.purs
Outdated
show (Rec a) = "(Rec " <> show a <> ")" | ||
|
||
instance showField :: (IsSymbol name, Show a) => Show (Field name a) where | ||
show (Field a) = "(Field \"" <> reflectSymbol (SProxy :: SProxy name) <> "\" " <> show a <> ")" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here please
👍 Thanks! |
What do you think about not providing a Show instance, but a monomorphic pretty printer instead. This way it can be DCE'd if it's not used and since it's main use is debugging it wouldn't become part of the interface of the Rep types. |
What type would it have? |
Oh I see... N monomoprhic pretty printers, but I guess that makes them more tedious to use. It's a little sad... I've been bitten by these random |
Would love to see this, or at least something like it, merged. Looks like it needs a rebase. |
I've reimplemented this in purescript/purescript-prelude#250 now that we've ported this repo to |
I've been trying to learn and understand this library, and I found it useful to be able to
show
the generic rep types that are returned byfrom
, to help visualise and understand the generic structure of a particular value.For example, using the types in
Test.Main
in psci:I had to add some missing dependencies and an install script to the
package.config
so I could build and run this project. I also added psci-support as a dev dependency to the bower.config, for being able to mess around with things in the interactive console. If you aren't cool with these changes, I've done them in separate commits so they can be reverted.