-
Notifications
You must be signed in to change notification settings - Fork 1.1k
[REPL] Add show capability to common types #1761
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
Conversation
7729c87
to
214258f
Compare
else "List(" + xs.map(_.show).mkString(", ") + ")" | ||
} | ||
|
||
implicit val showNil: Show[List[Nothing]] = new Show[List[Nothing]] { |
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.
Did you try defining Show[Nil]
and Show[None]
instead?
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 did, but I didn't push it! (=
It actually gives a better representation of list:
scala> Nil
val res0: scala.collection.immutable.Nil.type = Nil
scala> List()
val res1: List[Nothing] = List()
instead of printing Nil
for both.
See also the discussion in scala/scala#5222 |
LGTM 👍 |
This PR adds a
trait Show[-T]
to the Dotty library in order to print things in a better way for both the REPL and potentially other serializations. It also makes sure that the REPL shows all variables instead oftoString
ing them directly.For now, there's a default show instance that calls
toString
so that there's a fallback in case of aShow
instance not existing for a particular type. But potentially we could disallow printing things without aShow
instance in the future...Since we don't have control over the stdlib at the moment, we're stuck with providing default typeclass instances in the
dotty.Show
object. But ideally once @OlivierBlanvillain's HList implementation is in, perhaps we should investigate making aShow
instance forDottyProduct
or something similar so that we can have showing of all case classes 🎈A known shortcoming in this PR is with regards to union types in e.g:
I tried to make the default instance down cast things if possible, but that put me into overflows for certain cases. Perhaps I could try harder if we really want this before bootstrapped library...
review: @odersky | @smarter
merging this solves: #1681