add typeInference function, top-level that performs (deep) substitution on all sub-expressions