Skip to main content

A Compilation Method for Dynamic Typing in ML

  • Conference paper
  • First Online:
Programming Languages and Systems (APLAS 2021)

Part of the book series: Lecture Notes in Computer Science ((LNPSE,volume 13008))

Included in the following conference series:

  • 554 Accesses

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 to check access.

Access this chapter

Chapter
USD 29.95
Price excludes VAT (USA)
  • Available as PDF
  • Read on any device
  • Instant download
  • Own it forever
eBook
USD 64.99
Price excludes VAT (USA)
  • Available as EPUB and PDF
  • Read on any device
  • Instant download
  • Own it forever
Softcover Book
USD 84.99
Price excludes VAT (USA)
  • Compact, lightweight edition
  • Dispatched in 3 to 5 business days
  • Free shipping worldwide - see info

Tax calculation will be finalised at checkout

Purchases are for personal use only

Institutional subscriptions

References

  1. Abadi, M., Cardelli, L., Pierce, B., Rémy, D.: Dynamic typing in polymorphic languages. J. Funct. Program. 5(1), 111–130 (1995)

    Article  Google Scholar 

  2. 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)

    Article  Google Scholar 

  3. Atkinson, M., Buneman, O.: Types and persistence in database programming languages. ACM Comput. Surv. 19(2), 105–170 (1987)

    Article  Google Scholar 

  4. Chakravarty, M.M.T., Keller, G., Jones, S.P., Marlow, S.: Associated types with class. In: Proceedings ACM POPL, pp. 1–13 (2005)

    Google Scholar 

  5. Damas, L., Milner, R.: Principal type-schemes for functional programs. In: DeMillo, R.A. (ed.) In: Proceedings ACM POPL Symposium (1982)

    Google Scholar 

  6. Elsman, M.: Polymorphic equality - no tags required. In: Proceedings of the \(2nd\) International Workshop on Types in Compilation. Kyoto, March 1998

    Google Scholar 

  7. 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)

    Article  Google Scholar 

  8. Harper, R., Morrisett, G.: Compiling polymorphism using intensional type analysis. In: Proceedings ACM POPL Symposium, pp. 130–141 (1995)

    Google Scholar 

  9. Hengline, F.: Dynamic typing: syntax and proof theory. Science of Computer Programming (1992)

    Google Scholar 

  10. 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/

  11. 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

    Chapter  Google Scholar 

  12. Mitchell, J.C., Plotkin, G.D.: Abstract types have existential type. ACM Trans. Program. Lang. Syst. 10(3), 470–502 (1988)

    Article  Google Scholar 

  13. 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)

    Google Scholar 

  14. 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.)

    Google Scholar 

  15. 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)

    Google Scholar 

  16. Peyton Jones, S., Vytiniotis, D., Weirich, S., Washburn, G.: Simple unification-based type inference for GADTs. SIGPLAN Not. 41(9), 50–61 (2006)

    Article  Google Scholar 

  17. 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

    Chapter  MATH  Google Scholar 

  18. 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

    Chapter  Google Scholar 

  19. Schrijvers, T., Peyton Jones, S., Chakravarty, M., Sulzmann, M.: Type checking with open type functions. In: Proceedings ACM ICFP Conference, pp. 51–62 (2008)

    Google Scholar 

  20. Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Proceedings of the 2006 Scheme and Functional Programming Workshop, pp. 81–92 (2006)

    Google Scholar 

  21. SML# Project. https://smlsharp.github.io/en/

  22. 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)

    Google Scholar 

  23. Tolmach, A.: Tag-free garbage collection using explicit type parameters. In: Proceedings ACM Conference on LISP and Functional Programming, pp. 1–11 (1994)

    Google Scholar 

  24. Xi, H., Chen, C., Chen, G.: Guarded recursive datatype constructors. In: Proceedings ACM POPL Symposium, pp. 224–235 (2003)

    Google Scholar 

Download references

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

Authors

Corresponding author

Correspondence to Atsushi Ohori .

Editor information

Editors and Affiliations

Rights and permissions

Reprints and permissions

Copyright information

© 2021 Springer Nature Switzerland AG

About this paper

Check for updates. Verify currency and authenticity via CrossMark

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)

Publish with us

Policies and ethics