Substitution, record types and subtyping in type theory, with applications to the theory of programming