Move the type substitution functions from typing.ml to type.ml