Popis: |
This paper develops a systematic method for extending a polymorphic type system of ML with dynamic typing, and implements the extension in SML#. The core of the extension consists of an adaptation of the type-directed compilation method for non-parametric polymorphism to type tag abstraction and type tag generation. To support existentially bound type variables in dynamic value elimination and user-level manipulation of dynamic values, the conventional type-directed compilation framework is extended with existential types and a mechanism to reify dynamic values to user-level datatypes. The resulting language achieves orthogonal integration of dynamic typing in ML: it supports all the standard features, including polymorphic type inference, user-defined datatypes and pattern matching, in programming with dynamic typing. The implementation readily provides various practical features, including polymorphic first-class pretty-printer, polymorphic deserialization, type-safe interface to database systems, and type-safe meta-programming. |