type inference - Tuple2 mistakenly inferred as Product in recursive Scala function -


i've got function create combinations list of tuple2[char,int].

however when make recursive call on compile error, tuple inferred product.

why , how can compile?

here's code samples

this compiles ok:-

welcome scala version 2.10.1 (openjdk 64-bit server vm, java 1.7.0_17). type in expressions have them evaluated. type :help more information.  scala> def combos(a: list[(char,int)]): list[list[(char,int)]] = {      |     if(a.isempty) list(list()) else {      |       {      |         for{      |           x <- 0 a.length      |           (char,num) <- take x      |           rest = drop x      |           less <- num 1 -1                 |         } yield (char,less) :: rest      |       } tolist      |     }      |   } warning: there 1 feature warning(s); re-run -feature details combos: (a: list[(char, int)])list[list[(char, int)]] 

but recursive 1 fails.. see error @ bottom

welcome scala version 2.10.1 (openjdk 64-bit server vm, java 1.7.0_17). type in expressions have them evaluated. type :help more information.  scala> def combos(a: list[(char,int)]): list[list[(char,int)]] = {      |     if(a.isempty) list(list()) else {      |       {      |         for{      |           x <- 0 a.length      |           (char,num) <- take x      |           rest = combos(a drop x)      |           less <- num 1 -1                |         } yield (char,less) :: rest      |       } tolist       |     }      |   } <console>:17: error: type mismatch;  found   : list[list[product]]  required: list[list[(char, int)]]              } tolist                ^ 

thanks in advance.

the type of rest (the result of combos) list[list[(char,int)]] , you're appending (char,int) common inferred type product. maybe meant rest <- combos(a drop x) ?


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -