# Parameterized types used in varargs, how to define function value with such parameters?

**URL:** <https://users.scala-lang.org/t/parameterized-types-used-in-varargs-how-to-define-function-value-with-such-parameters/9462>\
**Category:** Question\
**Created:** [August 18, 2023, 8:24am UTC](https://users.scala-lang.org/t/parameterized-types-used-in-varargs-how-to-define-function-value-with-such-parameters/9462 "2023-08-18T08:24:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![guofengzh](https://users.scala-lang.org/user_avatar/users.scala-lang.org/guofengzh/32/1800_2.png) [@guofengzh](https://users.scala-lang.org/u/guofengzh)\
**Post date:** [August 18, 2023, 8:24am UTC](https://users.scala-lang.org/t/parameterized-types-used-in-varargs-how-to-define-function-value-with-such-parameters/9462/1 "2023-08-18T08:24:46Z")

</div>

Hi,

The arguments of the following functions use varargs that its type is parameterized types:

```auto
def f[A, AF](a: (A*) => AF) = ???
def f[A, AF]: (A*) => AF = ???

```

The above codes cannot be compiled by Scala 3.3.0

How to solve it?

Thanks for your help.

Guofeng

---

<div class="post-metadata">

**Author:** ![crater2150](https://users.scala-lang.org/user_avatar/users.scala-lang.org/crater2150/32/1011_2.png) [@crater2150](https://users.scala-lang.org/u/crater2150)\
**Post date:** [August 18, 2023, 9:07am UTC](https://users.scala-lang.org/t/parameterized-types-used-in-varargs-how-to-define-function-value-with-such-parameters/9462/2 "2023-08-18T09:07:17Z")

</div>

Varargs are just syntactic sugar for a `Seq` parameter, i.e. a function taking `A*` and returning `AF` would have the type `Seq[A] => AF`. Specifying the type as varargs is not supported. This means you can’t call a lambda function with variable arguments, but instead of `a(arg1, arg2, arg3)` you’ll have to write `a(Seq(arg1, arg2, arg3))` inside your method `f`.

You _can_ pass a varargs method when a function taking a Seq is expected, the following is valid:

```nohighlight
def f[A, AF](a: Seq[A] => AF) = ???

def varargMethod(ints: Int*): String = ???

f(varargMethod)

```

---

<div class="post-metadata">

**Author:** ![som-snytt](https://users.scala-lang.org/letter_avatar_proxy/v4/letter/s/7cd45c/32.png) [@som-snytt](https://users.scala-lang.org/u/som-snytt)\
**Post date:** [August 19, 2023, 6:43pm UTC](https://users.scala-lang.org/t/parameterized-types-used-in-varargs-how-to-define-function-value-with-such-parameters/9462/3 "2023-08-19T18:43:44Z")

</div>

The message is clearer in Scala 2.

```auto
Welcome to Scala 2.13.11 (OpenJDK 64-Bit Server VM, Java 20.0.1).
Type in expressions for evaluation. Or try :help.

scala> def f[A, AF](a: (A*) => AF) = ???
                          ^
       error: repeated parameters are only allowed in method signatures; use Seq instead

```

compare

```auto
Welcome to Scala 3.3.0 (20.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> def f[A, AF](a: (A*) => AF) = ???
-- [E040] Syntax Error: ------------------------------------------------------------------------------------------------
1 |def f[A, AF](a: (A*) => AF) = ???
  | ^
  | ')' expected, but identifier found

```

I’d like a worksheet or REPL that shows me results from both compilers.

Edit:

The issue for eta-expansion of method taking varargs was [this ticket](https://github.com/scala/bug/issues/4176). The lengthy discussions about what ought to be supported or disallowed make for interesting archaeology, a long answer to the OP. It is ten years since `-Yeta-expand-keeps-star` (in 2.10) was deprecated for 2.11.

The paulpism from a related ticket that is worth preserving, to capture the expectation that discussing a point must lead to clarity:

> spontaneous disambiguation

adriaanm’s coinage for the OP example:

> repeat offenders
