Abstract
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.
This is a preview of subscription content, log in via an institution.
Buying options
Tax calculation will be finalised at checkout
Purchases are for personal use only
Learn about institutional subscriptionsReferences
Abadi, M., Cardelli, L., Pierce, B., Rémy, D.: Dynamic typing in polymorphic languages. J. Funct. Program. 5(1), 111–130 (1995)
Abadi, M., Cardelli, L., Pierce, B., Plotkin, G.: Dynamic typing in a statically typed language. ACM Trans. Program. Lang. Syst. 13(2), 237–268 (1991)
Atkinson, M., Buneman, O.: Types and persistence in database programming languages. ACM Comput. Surv. 19(2), 105–170 (1987)
Chakravarty, M.M.T., Keller, G., Jones, S.P., Marlow, S.: Associated types with class. In: Proceedings ACM POPL, pp. 1–13 (2005)
Damas, L., Milner, R.: Principal type-schemes for functional programs. In: DeMillo, R.A. (ed.) In: Proceedings ACM POPL Symposium (1982)
Elsman, M.: Polymorphic equality - no tags required. In: Proceedings of the \(2nd\) International Workshop on Types in Compilation. Kyoto, March 1998
Hall, C.V., Hammond, K., Peyton Jones, S.L., Wadler, P.L.: Type classes in haskell. ACM Trans. Program. Lang. Syst. 18(2), 109–138 (1996)
Harper, R., Morrisett, G.: Compiling polymorphism using intensional type analysis. In: Proceedings ACM POPL Symposium, pp. 130–141 (1995)
Hengline, F.: Dynamic typing: syntax and proof theory. Science of Computer Programming (1992)
Leroy, X., Doligez, D., Frisch, A., Garrigue, J., Rémy, D., Vouillon, J.: The OCaml system release 4.10 documentation and user’s manual (2020). https://caml.inria.fr/pub/docs/manual-ocaml/
Leroy, X., Mauny, M.: Dynamics in ML. In: Hughes, J. (ed.) FPCA 1991. LNCS, vol. 523, pp. 406–426. Springer, Heidelberg (1991). https://doi.org/10.1007/3540543961_20
Mitchell, J.C., Plotkin, G.D.: Abstract types have existential type. ACM Trans. Program. Lang. Syst. 10(3), 470–502 (1988)
Ohori, A.: A simple semantics for ML polymorphism. In: Proceedings of ACM/IFIP Conference on Functional Programming Languages and Computer Architecture, pp. 281–292 (1989)
Ohori, A.: A polymorphic record calculus and its compilation. ACM Trans. Prog. Lang. and Syst. 17(6), 844–895 (1995) (An extended version of Ohori, A: A compilation method for ML-style polymorphic record calculi. ACM POPL Symposium, 154–165, 1992.)
Ohori, A., Ueno, K., Sasaki, T., Kikuchi, D.: A calculus with partially dynamic records for typeful manipulation of JSON objects. In: Proceedings ECOOP Conference (2016)
Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. SIGPLAN Not. 41(9), 50–61 (2006)
Peyton Jones, S., Weirich, S., Eisenberg, R.A., Vytiniotis, D.: A reflection on types. In: Lindley, S., McBride, C., Trinder, P., Sannella, D. (eds.) A List of Successes That Can Change the World. LNCS, vol. 9600, pp. 292–317. Springer, Cham (2016). https://doi.org/10.1007/978-3-319-30936-1_16
Pil, M.: Dynamic types and type dependent functions. In: Hammond, K., Davie, T., Clack, C. (eds.) IFL 1998. LNCS, vol. 1595, pp. 169–185. Springer, Heidelberg (1999). https://doi.org/10.1007/3-540-48515-5_11
Schrijvers, T., Peyton Jones, S., Chakravarty, M., Sulzmann, M.: Type checking with open type functions. In: Proceedings ACM ICFP Conference, pp. 51–62 (2008)
Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Proceedings of the 2006 Scheme and Functional Programming Workshop, pp. 81–92 (2006)
SML# Project. https://smlsharp.github.io/en/
Sulzmann, M., Chakravarty, M.M.T., Jones, S.P., Donnelly, K.: System F with type equality coercions. In: Proceedings ACM SIGPLAN International Workshop on Types in Languages Design and Implementation, pp. 53–66 (2007)
Tolmach, A.: Tag-free garbage collection using explicit type parameters. In: Proceedings ACM Conference on LISP and Functional Programming, pp. 1–11 (1994)
Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: Proceedings ACM POPL Symposium, pp. 224–235 (2003)
Acknowledgments
The authors thank an anonymous reviewer for his/her detailed comments. This work was partially supported by JSPS KAKENHI Grant Number JP18K11233. The second author’s work was also partially supported by JSPS KAKENHI Grant Number JP19K11893.
Author information
Authors and Affiliations
Corresponding author
Editor information
Editors and Affiliations
Rights and permissions
Copyright information
© 2021 Springer Nature Switzerland AG
About this paper
Cite this paper
Ohori, A., Ueno, K. (2021). A Compilation Method for Dynamic Typing in ML. In: Oh, H. (eds) Programming Languages and Systems. APLAS 2021. Lecture Notes in Computer Science(), vol 13008. Springer, Cham. https://doi.org/10.1007/978-3-030-89051-3_9
Download citation
DOI: https://doi.org/10.1007/978-3-030-89051-3_9
Published:
Publisher Name: Springer, Cham
Print ISBN: 978-3-030-89050-6
Online ISBN: 978-3-030-89051-3
eBook Packages: Computer ScienceComputer Science (R0)