Move some utility functions from typing.ml to type.ml