Search code examples
scalatuplesscala-collectionstypingstatic-typing

Defining Tuple types


For this type :

val t :  (String, Array[((String, String), Double)]) =  ("a", Array((("a", "b"), 1.0), (("a", "c"), 2.0)))

should I not be able to use also this type definition :

val t : Tuple2[String , Array[Tuple2[[String , String] , Double]]] = ("a", Array((("a", "b"), 1.0), (("a", "c"), 2.0)))

But receive this error :

Multiple markers at this line - identifier expected but '[' found. - wrong number of type arguments for Tuple2, 
 should be 2 - only classes can have declared but undefined members

Is Tuple2 (or TupleN) not allowed when defining a type ?


Solution

  • Your problem specifically there:

    Tuple2[[String , String] , Double]]
    

    [String, String] is a nonsense, you probably wanted Tuple2[Tuple2[String , String] , Double]], or ((String , String) , Double)