PartialFunction type inference in Scala -


let's consider following function:

def printpftype[t](pf:partialfunction[t, _])(implicit m:manifest[t]) = {   println(m.tostring) } 

then define following test class:

case class test(s:string, i:int) 

i can't write this:

printpftype {   case test(_,i) => } 

because compiler can't infer first parametric type of partialfunction. have specify explicitly:

printpftype[test] {   case test(_,i) => } 

but test type appears twice. there technique avoid this? how can type inferer avoid duplicate?

see thread. type inference cannot handle problem. quote spec:

an anonymous function can defined sequence of cases { case p1 => b1 . . . case pn => bn } appear expression without prior match. the expected type of such expression must in part defined. must either scala.functionk[s1, . . . , sk, r] k > 0, or scala.partialfunction[s1, r], argument type(s) s1, . . . , sk must determined, result type r may undetermined.


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -