Skip to content

[_tour/multiple-parameter-lists.md] type inference example is incorrect for Scala 3 #3248

Description

@aligusnet

This example claims that type inference is not possible for the code below:

def foldLeft1[A, B](as: List[A], b0: B, op: (B, A) => B) = ???

def notPossible = foldLeft1(numbers, 0, _ + _)

However, this seems to be inaccurate for Scala 3, here's the example which works fine with Scala 3.0.0+:

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) =
  var res = b0
  for a <- as do
    res = op(res, a)
  res

def notPossible = foldLeft1(numbers, 0, _ + _)
println(notPossible) // prints 55

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions