The connection between polymorphic and dynamic typing was originally considered by Curry, et al. in the form of "polymorphic type assignment" for untyped λ-terms. Types are assigned after the fact to what is, in modern terminology, a dynamic language. Interest in type assignment was revitalized by the proposals of Bracha, et al. and Bank, et al. to enrich Java with polymorphism (generics), which in turn sparked the development of other languages, such as Scala, with similar combinations of features. In that setting it is desirable to compile polymorphism to dynamic typing in such a way that as much static typing as possible is preserved, relying on dynamics only insofar as genericity is actually required. Although this approach seems intuitively plausible, we have found it surprisingly difficult to state and prove its correctness. To get a handle on the difficulties we study the compilation of System F to an extension of PCF with a dynamic type, dyn. Inspired by Meyer and Wand's proof of correctness for the CPS transform, a natural strategy is to establish an embedding of all types into the type dyn, and to use the corresponding projection at appropriate points to recover the embedded value. One would then use this embedding to establish a logical relation between the source and target languages to obtain an observational equivalence result for the compilation. Surprisingly, this approach does not appear to be applicable to the present setting, and we have instead devised an alternative, also based on logical relations, to establish the correctness of the compilation.
REF prove the correctness of compiling polymorphism to dynamic typing with embeddings and partial projections; the compilation setting however differs significantly from gradual typing.
Correctness of Compiling Polymorphism to Dynamic Typing
J. Funct. Program.
J. Funct. Program.
Computer Science