Skip to content

Complete daniel-chambers' PR adding Show instances to generics rep types #250

New issue

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

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

Already on GitHub? # to your account

Merged
merged 4 commits into from
Dec 26, 2020
Merged

Complete daniel-chambers' PR adding Show instances to generics rep types #250

merged 4 commits into from
Dec 26, 2020

Conversation

JordanMartinez
Copy link
Contributor

Completes the PR he started in purescript-deprecated/purescript-generics-rep#11

Helps one see the generic representation for a given value
Comment on lines 126 to 128
assert "Checking show for generic types" $
show (G.from $ cons 1 Nil) == "(Inr (Constructor \"Cons\" (Argument { head: 1, tail: Nil })))"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we also test the show output for G.from Nil to cover NoArguments and the Inl constructor, as well as a constructor with multiple arguments to cover Product?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. Fixed.

-- | A representation for constructors which includes the data constructor name
-- | as a type-level string.
newtype Constructor (name :: Symbol) a = Constructor a

instance showConstructor :: (IsSymbol name, Show a) => Show (Constructor name a) where
show (Constructor a) = "(Constructor " <> show (reflectSymbol (Proxy :: Proxy name)) <> " " <> show a <> ")"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can I request that we put a @ symbol before the constructor name? It wouldn’t be valid syntax (we don’t have explicit type applications) but it does at least clarify that the string isn’t an actual constructor argument for Constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Meaning this? Yeah, I think that makes sense.

- "(Constructor " <> show (reflectSymbol ...
+ "(Constructor @" <> show (reflectSymbol ...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, exactly that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@JordanMartinez JordanMartinez merged commit d3cdad1 into purescript:master Dec 26, 2020
@JordanMartinez JordanMartinez deleted the showReps branch December 26, 2020 17:14
turlando pushed a commit to purescm/purescript-prelude that referenced this pull request Sep 3, 2021
…pes (purescript#250)

* Add Show instance to generic rep types (complete daniel-chambers PR)

Helps one see the generic representation for a given value

* Add `@` in front of constructor name in Show instance for generic type

* Add tests for Inl, NoArguments, and Product
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants