Implement type inference for patterns.