Foundations And Applications Of Modal Type Theories