Skip to content
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

Multiple Parameter Lists Doc is no longer accurate w.r.t. type inference #3163

Open
amordahl opened this issue Feb 19, 2025 · 0 comments
Open

Comments

@amordahl
Copy link

amordahl commented Feb 19, 2025

The page for multiple parameter lists shows one use case of multiple parameter lists being to drive type inference, and it shows an example that it claims does not compile in Scala 2 or 3:

val numbers = List(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
def foldLeft1[A, B](as: List[A], b0: B, op: (B, A) => B) = ???

// docs.scala-lang says this should not compile, but it works fine.
def notPossible = foldLeft1(numbers, 0, _ + _)

I gather there have been a number of improvements to Scala's type inference, such that in both Scala 3 LTS (3.3.5) and Scala 3 Next (3.6.3), the above code compiles and infers the type of notPossible perfectly fine.

Unfortunately, I'm not familiar enough with Dotty's type inference to know whether or not driving type inference is still an important use case for multiple parameter lists; I suggest that we either/both:

  1. Come up with a new example that fails in current Scala 3, and/or
  2. Emphasize the following use cases, which I think are more common in modern Scala 3 code:
  • Partial function application (which is already discussed in the doc),
  • The ability to create syntax similar to control structures, including braceless lambdas (which is not discussed in the doc).

I would be happy to update the page and make a PR, but I wasn't sure if somebody more familiar with the current type inference algorithm could come up with a replacement example.

@amordahl amordahl changed the title Multiple Parameter Lists Doc is no longer accurate. Multiple Parameter Lists Doc is no longer accurate w.r.t. type inference Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant