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

Add a type class for showing values at elaboration time #724

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

krame505
Copy link
Contributor

There isn't currently really a great way of printing out structured data at elaboration time for debugging purposes. I made a type class SShow mirroring CShow, except that it generates a String instead of Fmt for printing at elaboration time.

@quark17
Copy link
Collaborator

quark17 commented Oct 17, 2024

I had commented offline that it's unfortunate that this SShow library duplicates so much from CShow and wondered if one could be defined in terms of the other. I think I suggested that a function from Fmt to String could be used to define SShow, but I think you responded by pointing out that non-runtime types like List wouldn't have CShow instances. So then what about the other direction -- can we define CShow as just printing the string from SShow? Or can the choice of show versus $format be abstracted out, to have a common underlying polymorphic implementation? If not, this amount of redundancy isn't too bad, so I'm OK with accepting the PR as it is, if that's easiest.

FYI, I notice that there's no instance for the Array primitive -- is that possible to add?

@quark17
Copy link
Collaborator

quark17 commented Oct 17, 2024

Oh, also, could you add a test case?

@krame505
Copy link
Contributor Author

There isn't a way to go from a runtime value to an elaboration-time String, either. If we had a typeclass StringLike like in Haskell, we could maybe abstract out the generic bit for showing data/structs/vectors, but I'm not sure how to define the primitive instances in that approach.

@krame505
Copy link
Contributor Author

I added the Array instance and some test cases.

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 this pull request may close these issues.

2 participants