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
repl :kind command is misleading and underdocumented #8529
Comments
Imported From: https://issues.scala-lang.org/browse/SI-8529?orig=1 |
@som-snytt said:
Happy Shakespeare's birthday. |
@SethTisue said: |
Fixes scala/bug#8529 The :kind implementation added in scala#2340 was buggy and misleading in part because we could not find a robust way to turning type expression strings into Type. See also http://stackoverflow.com/questions/15678616/getting-type-information-inside-scala-repl-via-imain/15694003#15694003. The problem was that we didn't know how to pick up types defined in the REPL, so scala#2340 faked it by treating the expression as a term. That's the major source of problems reported in scala/bug#8529. This change improves the String to type symbol conversion by using `exprTyper.typeOfTypeString` repeatedly with `[Nothing]`. It's hacky, but a whole class of "expression" can now be called out as not being a type. Before: scala> :kind 5 scala.Int's kind is A After: scala> :kind 5 <console>:1: error: identifier expected but integer literal found. def $ires23: 5 = ??? ^ More importantly, it will no longer mix up companion objects with actual types. Before: scala> :kind -v Predef.Pair scala.Predef.Pair's kind is A * This is a proper type. After: scala> :kind -v Predef.Pair scala.Tuple2's kind is F[+A1,+A2] * -(+)-> * -(+)-> * This is a type constructor: a 1st-order-kinded type.
Fixes scala/bug#8529 The :kind implementation added in scala#2340 was buggy and misleading in part because we could not find a robust way to turn a type expression string into a Type. See also [Getting type information inside scala repl via IMain](http://stackoverflow.com/questions/15678616/getting-type-information-inside-scala-repl-via-imain/15694003#15694003). The problem was that we didn't know how to pick up types defined or imported in the REPL, so scala#2340 faked it by treating the given type expression as a term. That's the major source of problems reported in scala/bug#8529. This commit improves the String to type symbol conversion by using `exprTyper.typeOfTypeString` repeatedly with `[Nothing]`. It's hacky, but a whole class of "expression" can now be called out as not being a type. Before: scala> :kind 5 scala.Int's kind is A After: scala> :kind 5 <console>:1: error: identifier expected but integer literal found. def $ires23: 5 = ??? ^ More importantly, it will no longer mix up companion objects with actual types. Before: scala> :kind -v Predef.Pair scala.Predef.Pair's kind is A * This is a proper type. After: scala> :kind -v Predef.Pair scala.Tuple2's kind is F[+A1,+A2] * -(+)-> * -(+)-> * This is a type constructor: a 1st-order-kinded type.
Fixes scala/bug#8529 The :kind implementation added in scala#2340 was buggy and misleading in part because we could not find a robust way to turn a type expression string into a Type. See also [Getting type information inside scala repl via IMain](http://stackoverflow.com/questions/15678616/getting-type-information-inside-scala-repl-via-imain/15694003#15694003). The problem was that we didn't know how to pick up types defined or imported in the REPL, so scala#2340 faked it by treating the given type expression as a term. That's the major source of problems reported in scala/bug#8529. This commit improves the String to type symbol conversion by using `exprTyper.typeOfTypeString` repeatedly with `[Nothing]`. It's hacky, but a whole class of "expression" can now be called out as not being a type. Before: scala> :kind 5 scala.Int's kind is A After: scala> :kind 5 <console>:1: error: identifier expected but integer literal found. def $ires23: 5 = ??? ^ More importantly, it will no longer mix up companion objects with actual types. Before: scala> :kind -v Predef.Pair scala.Predef.Pair's kind is A * This is a proper type. After: scala> :kind -v Predef.Pair scala.Tuple2's kind is F[+A1,+A2] * -(+)-> * -(+)-> * This is a type constructor: a 1st-order-kinded type.
Fixes scala/bug#8529 The :kind implementation added in scala#2340 was buggy and misleading in part because we could not find a robust way to turn a type expression string into a Type. See also [Getting type information inside scala repl via IMain](http://stackoverflow.com/questions/15678616/getting-type-information-inside-scala-repl-via-imain/15694003#15694003). The problem was that we didn't know how to pick up types defined or imported in the REPL, so scala#2340 faked it by treating the given type expression as a term. That's the major source of problems reported in scala/bug#8529. This commit improves the String to type symbol conversion by using `exprTyper.typeOfTypeString` repeatedly with `[Nothing]`. It's hacky, but a whole class of "expression" can now be called out as not being a type. Before: scala> :kind 5 scala.Int's kind is A After: scala> :kind 5 <console>:1: error: identifier expected but integer literal found. def $ires23: 5 = ??? ^ More importantly, it will no longer mix up companion objects with actual types. Before: scala> :kind -v Predef.Pair scala.Predef.Pair's kind is A * This is a proper type. After: scala> :kind -v Predef.Pair scala.Tuple2's kind is F[+A1,+A2] * -(+)-> * -(+)-> * This is a type constructor: a 1st-order-kinded type.
Fixes scala/bug#8529 The :kind implementation added in scala#2340 was buggy and misleading in part because we could not find a robust way to turn a type expression string into a Type. See also [Getting type information inside scala repl via IMain](http://stackoverflow.com/questions/15678616/getting-type-information-inside-scala-repl-via-imain/15694003#15694003). The problem was that we didn't know how to pick up types defined or imported in the REPL, so scala#2340 faked it by treating the given type expression as a term. That's the major source of problems reported in scala/bug#8529. This commit improves the String to type symbol conversion by using `exprTyper.typeOfTypeString` repeatedly with `[Nothing]`. It's hacky, but a whole class of "expression" can now be called out as not being a type. Before: scala> :kind 5 scala.Int's kind is A After: scala> :kind 5 <console>:1: error: identifier expected but integer literal found. def $ires23: 5 = ??? ^ More importantly, it will no longer mix up companion objects with actual types. Before: scala> :kind -v Predef.Pair scala.Predef.Pair's kind is A * This is a proper type. After: scala> :kind -v Predef.Pair scala.Tuple2's kind is F[+A1,+A2] * -(+)-> * -(+)-> * This is a type constructor: a 1st-order-kinded type.
I corrected the broken behaviors in scala/scala#5916, so it should now align with the standard notion of kind.
Yea. scala/scala#5916 will reject term expressions like
I figured out a way to get to the type constructor without going through terms, so
Yes fully applied type should be |
Some of the results from :kind are difficult to justify. The sum total of the documentation I can find is "display the kind of expression's type" so if there is some non-standard notion of kind (and/or expression) being applied here it would be nice to document it. The one line of documentation is already on shaky ground - all expressions (as the word is normally used) have the same kind.
There is more confusion as to whether :kind is providing the kind of an "expression" or of a "type". As the kind of an expression is uninteresting, it should interpret the input as describing an unapplied type whenever possible. But in the following example it prefers the expression meaning over the type-constructor meaning, which leads to absurdity.
Here are some more anomalies noted in brief experimentation.
The text was updated successfully, but these errors were encountered: