Why are variables not allowed in alternative patterns?
问题 Often you have "symmetric" matches and want to write things like: def g(p:(Int,Int)) = p match { case (10,n) | (n,10) => println(n) case _ => println("nope") } This is not allowed, but if every alternative has the same variables with the same types , this shouldn't be a problem, as it could be translated to separate cases: def g(p:(Int,Int)) = p match { case (10,n) => println(n) case (n,10) => println(n) case _ => println("nope") } So why do we have this restriction? 回答1: Likely because it