-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Specify impl for Show[Symbol]
#4490
Open
LeifW
wants to merge
1
commit into
typelevel:main
Choose a base branch
from
LeifW:explicit_symbol_show
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Or maybe this should just be
.name
- without the leading'
? I think ofShow
as being something nice / sane for humans to read - we have.toString
for diagnostic / debug output...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.
I think this isn't safe since Symbol("foo bar") is allowed I think.
Instead I think we should check if the name is a valid Symbol literal (somehow, maybe regex?) and then we could use the '
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.
Not understanding what the issue is - what does being a valid 2.12 Symbol literal have to do with the
Show
representation? Is there a restriction thatShow
has to emit valid Scala source code? It already breaks that on theShow
representation for String.'foo bar
is a valid string. That's the.toString
ofSymbol
in Scala 2.12.All this PR does is fix the
Show
implementation to the version already present on 2.12 - by inlining 2.12's definition ofSymbol.toString
: https://github.com/scala/scala/blob/2.12.x/src/library/scala/Symbol.scala#L30There 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.
My concern is that imagine you interpolate this into a string, it would be ambiguous even to a human where the symbol ends.
As such I think it is a bad default.
Show is a lawless typeclass anyway, so I think there is an excellent argument it shouldn't exist in cats but maybe alleycats.
I'd rather see a typeclass more about encoding and decoding into strings. Like a pretty printer + parser. Such a typeclass can be lawful.
Here it's all bikeshed it seems. So I totally understand if you prefer a different bikeshed color.
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.
This is literally already the current
Show[Symbol]
impl on 2.12. Having different goals forShow
seems outside the scope of this PR. I don't care what it is, so long as it's consistent. Do you have any alternate suggestions? 2.13'sSymbol(foo)
? Or no decoration, justfoo
?On Haskell there's perhaps a convention of read . show = id, but I don't see either of those typeclasses mention that explicitly, Read is bad anyways, and there's no Read in Cats. I can't see any "rules" for what the expected Show output is - I gather it's just intended to give a string intended for human readability. I gather the convention is to roughly follow existing
.toString
representations. I see Kittens adds labels to case class parameters - still looks almost like Scala source. Are you proposing a novel string representation for Symbols, or just that Show shouldn't exist here in the first place, or...?There are much better solutions if you expect machine-parsible output - the current Show impls break any hope of that all over the place already (e.g. strings are not quoted).
Redesigning the entire Show typeclass / documentation with the expectation of machine parseability isn't something I'm interested in (especially not for this PR).
I'm not proposing a different bikeshed color, I just want it to be the same across Scala versions.
Your concern about a human "not being able to tell where the symbol ends" already exists in Show and .toString for Symbol on 2.12, as well as Show[Symbol] for all Scala versions, etc. See the Show output at the end of the box on https://github.com/typelevel/kittens#derive-show.
That Show output is not valid Scala source code, nor is it intended to be. It's a human-readable representation of the value it was called on.
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.
As far as the
Show
instance forSymbol
, would you prefer:'foo bar
(the current impl for 2.12)Symbol(foo bar)
(the current impl for 2.13)'foo
and sometimesSymbol(foo bar)
?The only thing his PR is trying to do is to make that impl consistent across Scala versions. I'm not interested in redesigning / removing the
Show
typeclass on this PR.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.
Related (there's no Read typeclass - Show is for human-readable output, not intended to be machine-parseable): #932 (comment)