-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?

1
  • 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 Commented Feb 18, 2023 at 15:13

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Okay I found a way:

var walls = Array[(Int, Int)]()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.