1

I am reading a great book Programming in Scala by Martin Odersky (creator of Scala) and others.

There comes up the chapter 9.3 Currying where currying is introduced. This leads me to the question, is there some limit to the number of parameter lists a Scala 3 function can have? Follow-up question: if there is/n't a limit, why?


For example, the following Scala 3 snippet compiles just fine.
There is a function curriedSum with 5 parameter lists (it is only for illustration, every sane programmer would use a single parameter list).

def curriedSum(a: Int)(b: Int)(c: Int)(d: Int)(e: Int) = a + b + c + d + e
curriedSum(1)(2)(3)(4)(5) // 15

version without currying

def ordinarySum(a: Int, b: Int, c: Int, d: Int, e: Int) = a + b + c + d + e
ordinarySum(1, 2, 3, 4, 5) // 15
Talos
  • 457
  • 4
  • 15
  • 1
    If there is a limit is far from anything practical and realistic, so I wouldn't care. – Luis Miguel Mejía Suárez Dec 31 '22 at 17:28
  • 2
    From JVM point of view both versions of `curriedSum`/`ordinarySum` have 5 parameters. There is JVM limit how many parameters a method can have totally. – Dmytro Mitin Dec 31 '22 at 17:54
  • 5
    It's 255 https://stackoverflow.com/questions/30581531/maximum-number-of-parameters-in-java-method-declaration So there can be no more than 255 parameter lists if they are single-parameter or 128 lists if they are two-parameter etc. – Dmytro Mitin Dec 31 '22 at 17:57

0 Answers0