I already found that it is possible to bind the type parameter in a pattern matching
Why does not that work in that case ?
trait T
case class S[A](a: A) extends T
def pr(t1: T, t2: T) = (t1, t2) match {
case (S(a): S[ta], S(b): S[tb]) => println(a); println(b)
}
^
error: '=>' expected but ':' found.
For information, this works:
def pr(t1: T, t2: T) = (t1, t2) match {
case (s1: S[a], s2: S[b]) => println(s1.a); println(s2.a)
}
And this as well:
def pr(t1: T, t2: T) = (t1, t2) match {
case (S(a), S(b)) => println(a); println(b)
}
I need to recover the type to define other functions whose type cannot be inferred because in the context of eta-expansion.
UPDATE
As mentionned in the comments, I need the types just for correct type checking, not anything else.
For example:
trait T
case class S[A](a: A, w: A => Int) extends T
def makeTwo(t1: T, t2: T) = (t1, t2) match {
case (S(a1, w1), S(a2, w2)) =>
val wNew = { (a, b) => w1(a) + w2(b) }
S((a, b), wNew)
}
error: missing parameter type
val wNew = { (a, b) => w1(a) + w2(b) }
^