Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Jan 17, 2025

This is a tweak to the named tuple spec and implementation. If the expected type is a case class,
expand a named tuple to a call of the apply method of the case class.

Based on #21993. Only the last commit is relevant.

A test case that shows that we can have an "inline type class" that allows
to use a typeclass-based scheme for sequence literals where instances can
be created with macros.
Also: Move test to run
We now don't try to instantiate selected type variables. Instead, we use a default as fallback if
the expected type is underspecified according to the definition in Implicits. This is
simpler and more expressive.
Also, test infix operations taking [...] as a right operand.
Some corrections in docs, fix typos, drop unused code.
This is a tweak to the named tuple spec. If the expected type is a case class
expand to a call of its apply method.
val anotherLit: IArray[Double] = [math.Pi, math.cos(2.0), math.E * 3.0]
val diag: Array[Array[Int]] = [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
val empty: ArrayBuffer[Object] = []
val mapy: HashMap[Int, String] = [1 -> "one", 2 -> "two", 3 -> "three"]
Copy link
Contributor

Choose a reason for hiding this comment

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

I more like Dartlang's syntax for this, here, [] is an Array, which makes me think the KEY can be REPEATED, but actually, it isn't.

val mapy: HashMap[Int, String] = [1 -> "one", 2 -> "two", 3 -> "three"] can be
val mapy: Array[(Int, String)] = [1 -> "one", 2 -> "two", 3 -> "three"]

but if you chose Dart's syntax, then the HashMap[Int, String] can be omitted.

val mapy = {1 -> "one", 2 -> "two", 3 -> "three"} is a map or
val mapy = {1 : "one", 2 : "two", 3 :"three"} is a map too.

Copy link
Contributor

Choose a reason for hiding this comment

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

When all are [], you lose the information of if the element or key can be repeated, and then you have to annotate the result type explicitly, which is not how Scala's works, a well static typed language as a dynamic language, and now, with [] everywhere, we are writing plain old Java.

@tgodzik tgodzik added the needs-sip A SIP needs to be raised to move this issue/PR along. label Jan 20, 2025
@odersky
Copy link
Contributor Author

odersky commented Feb 16, 2025

Closing to relieve the PR queue. We can come back to this later.

@odersky odersky closed this Feb 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-sip A SIP needs to be raised to move this issue/PR along.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants