Soft Typing
📜 Abstract
In an effort to avoid improper use of program functions, modern programming languages employ some kind of preventative type system. These type systems can be classified as either static or dynamic. Static type systems detect "ill-typed" program phrases at compile-time, whereas dynamic type systems detect "ill-typed" phrases at run-time. Static typing systems have two important advantages over dynamically typed systems: First, they provide important feedback to the programmer by detecting a large class of program errors before execution. Second, they extract information that a compiler can exploit to produce more efficient code. The price paid for these advantages, however, is a loss of expressiveness and modularity. It is easy to prove that a static type system for an "interesting" programming language necessarily excludes some "good" programs. This paper focuses on the problem of designing programming systems that retain the all the expressiveness of dynamic typing, but still offer the early error detection and improved optimization opportunities of static typing. To that end, we introduce a concept called soft typing. The key concept of soft typing is that a type checker need not reject programs containing statically "ill-typed" phrases. Instead, the soft type checker inserts explicit run-time checks. Thus, there are two issues to be addressed in the design of soft typing systems. First, the typing mechanism must provide reasonable feedback to programmers accustomed to dynamically typed-languages. Current static systems fail to satisfy the programmer's intuition about correctness on many programs. Second, a soft typing system must sensibly insert run-time checks (when necessary). This paper develops a type system and checking algorithms that are suitable for soft typing a significant class of programming languages.
✨ Summary
The paper introduced soft typing, an alternative to purely static or purely dynamic typing. Its central technique is to infer types without rejecting programs that cannot be completely typed, inserting explicit run-time checks where static analysis is insufficient. The proposed system extends Hindley–Milner-style inference with union and recursive types. Metadata sources identify the work as a PLDI ’91 paper by Robert Cartwright and Mike Fagan, presented in Toronto on June 26–28, 1991. (dblp.dagstuhl.de)
Subsequent work extended the approach to Scheme features such as mutation and continuations, developed more precise set-based analyses used in the DrScheme/MrFlow ecosystem, and applied related soft-typing ideas to exception analysis. Later research explicitly treats soft typing as an early foundation for gradual and hybrid typing, including systems for Scheme and conditional-type inference. (cs.rice.edu)