Implement type inference for pattern matching in the new algorithm.