TypeInference: rewritten substitute to have better semantics