E023: Wrong Number Of Type Args
This error is emitted when a type constructor is applied with the wrong number of type arguments.
Each generic type has a specific number of type parameters. For example:
List[A]takes exactly one type parameterMap[K, V]takes exactly two type parametersEither[L, R]takes exactly two type parameters
You must provide exactly the number of type arguments that the type expects.
Example
val x: List[Int, String] = List()
Error
-- [E023] Syntax Error: example.scala:1:7 --------------------------------------
1 |val x: List[Int, String] = List()
| ^^^^^^^^^^^^^^^^^
| Too many type arguments for List[A]
| expected: [A]
| actual: [Int, String]
|-----------------------------------------------------------------------------
| Explanation (enabled by `-explain`)
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
| You have supplied too many type parameters
|
| For example List takes a single type parameter (List[A])
| If you need to hold more types in a list then you need to combine them
| into another data type that can contain the number of types you need,
| In this example one solution would be to use a Tuple:
|
| val tuple2: (Int, String) = (1, "one")
| val list: List[(Int, String)] = List(tuple2)
-----------------------------------------------------------------------------
Solution
// Use the correct number of type arguments
val x: List[Int] = List()
// For multiple types, use a tuple or a different container
val x: List[(Int, String)] = List()
// Or use a type that takes multiple parameters
val x: Map[Int, String] = Map()
// Or use Either for two alternatives
val x: Either[Int, String] = Right("hello")
In this article