-1

Im trying to create an empty Array to store coordinates of an object in an Tuple which is then stored in an Array.

When I try:

var walls = Array[Tuple2]()

Im getting this error message:

kinds of the type arguments (Tuple2) do not conform to the expected kinds of the type parameters (type T).
[error] Tuple2's type parameters do not match type T's expected parameters:
[error] class Tuple2 has two type parameters, but type T has none
[error]         var walls = Array[Tuple2]()

Is there any possibility to do this?

TamZ
  • 27
  • 3
  • 3
    You want something like `Array.empty[(Int, Int)]` or whatever type your coordinates will have. - also, you probably want to remove the two layers of mutability as well as avoid using `Arrays` – Luis Miguel Mejía Suárez Feb 18 '23 at 15:13

2 Answers2

4

Tuple2 is a type constructor (of kind [*, *] => *).

Array is a type constructor too (of kind [*] => *).

You have to apply Tuple2 to two types (of kind *) in order to make it suitable as an argument of Array.

That's why Array[(Int, Int)] aka Array[Tuple2[Int, Int]] is working while Array[Tuple2] is not.

Dmytro Mitin
  • 48,194
  • 3
  • 28
  • 66
2

Okay I found a way:

var walls = Array[(Int, Int)]()
TamZ
  • 27
  • 3