Skip to main content
Log in

Space-efficient gradual typing

  • Published:
Higher-Order and Symbolic Computation

Abstract

Gradual type systems offer a smooth continuum between static and dynamic typing by permitting the free mixture of typed and untyped code. The runtime systems for these languages, and other languages with hybrid type checking, typically enforce function types by dynamically generating function proxies. This approach can result in unbounded growth in the number of proxies, however, which drastically impacts space efficiency and destroys tail recursion.

We present a semantics for gradual typing that is based on coercions instead of function proxies, and which combines adjacent coercions at runtime to limit their space consumption. We prove bounds on the space consumed by coercions as well as soundness of the type system, demonstrating that programmers can safely mix typing disciplines without incurring unreasonable overheads. Our approach also detects certain errors earlier than prior work.

This is a preview of subscription content, log in via an institution to check access.

Access this article

Price excludes VAT (USA)
Tax calculation will be finalised during checkout.

Instant access to the full article PDF.

Similar content being viewed by others

References

  1. Ahmed, A., Findler, R.B., Matthews, J., Wadler, P.: Blame for all. In: Workshop on Script to Program Evolution (2009)

    Google Scholar 

  2. Birtwhistle, G.M., et al.: Simula Begin. Chartwell-Bratt Ltd., Bromley (1979)

    Google Scholar 

  3. Blume, M., McAllester, D.: Sound and complete models of contracts. J. Funct. Program. 16(4–5), 375–414 (2006). ISSN 0956-7968. doi:10.1007/s10990-011-9066-z

    Article  MathSciNet  MATH  Google Scholar 

  4. Bracha, G.: Pluggable type systems. In: Workshop on Revival of Dynamic Languages, October 2004

    Google Scholar 

  5. Brus, T., van Eekelen, M., van Leer, M., Plasmeijer, M.: Clean nnn a language for functional graph rewriting. In: Kahn, G. (ed.) Functional Programming Languages and Computer Architecture. Lecture Notes in Computer Science, vol. 274, pp. 364–384. Springer, Berlin (1987)

    Google Scholar 

  6. Cardelli, L.: Amber. In: Spring School of the LITP on Combinators and Functional Programming Languages, pp. 21–47 (1986)

    Google Scholar 

  7. Cardelli, L., Donahue, J., Glassman, L., Jordan, M., Kalsow, B., Nelson, G.: Modula-3 report (revised). Technical Report 52, DEC SRC (1989)

  8. Chambers, C.: The Cecil Language Specification and Rationale: Version 3.0. University of Washington (1998)

  9. Clements, J.: Portable and high-level access to the stack with Continuation Marks. PhD thesis, Northeastern University (2005)

  10. Clements, J., Felleisen, M.: A tail-recursive machine with stack inspection. ACM Trans. Program. Lang. Syst. 26(6), 1029–1052 (2004)

    Article  Google Scholar 

  11. de Oliveira, R.B.: The Boo programming language (2005)

  12. ECMAScript Edition 4 group wiki. Ecma International (2007)

  13. ECMAScript Language Specification. Ecma International, 5th edn. (2009). URL http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-262.pdf

  14. Findler, R.B., Blume, M.: Contracts as pairs of projections. In: Proceedings of the International Symposium on Functional and Logic Programming (FLOPS), pp. 226–241 (2006)

    Chapter  Google Scholar 

  15. Findler, R.B., Felleisen, M.: Contracts for higher-order functions. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP), pp. 48–59, October 2002

    Google Scholar 

  16. Flanagan, C.: Hybrid type checking. In: Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pp. 245–256 (2006)

    Google Scholar 

  17. Flanagan, C., Freund, S.N., Tomb, A.: Hybrid types, invariants, and refinements for imperative objects. In: The International Workshop on Foundations and Developments of Object-Oriented Languages (FOOL/WOOD) (2006)

    Google Scholar 

  18. Ganz, S.E., Friedman, D.P., Wand, M.: Trampolined style. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP), pp. 18–27 (1999)

    Google Scholar 

  19. Greenberg, M., Pierce, B., Weirich, S.: Contracts made manifest. In: Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (2010)

    Google Scholar 

  20. Gronski, J., Knowles, K., Tomb, A., Freund, S.N., Flanagan, C.: Sage: Hybrid checking for flexible specifications. In: Scheme and Functional Programming Workshop, September 2006

    Google Scholar 

  21. Guha, A., Matthews, J., Findler, R.B., Krishnamurthi, S.: Relationally-parametric polymorphic contracts. In: DLS, pp. 29–40 (2007)

    Chapter  Google Scholar 

  22. Henglein, F.: Dynamic typing: Syntax and proof theory. Sci. Comput. Program. 22(3), 197–230 (1994)

    Article  MathSciNet  MATH  Google Scholar 

  23. Herman, D., Tomb, A., Flanagan, C.: Space-efficient gradual typing. In: Trends in Functional Programming (TFP) (2007)

    Google Scholar 

  24. Knowles, K.W., Flanagan, C.: Hybrid type checking. ACM Trans. Program. Lang. Syst. 32(2) (2010)

  25. Matthews, J., Findler, R.B.: Operational semantics for multi-language programs. In: Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (2007)

    Google Scholar 

  26. Meijer, E., Drayton, P.: Static typing where possible, dynamic typing when needed. In: Workshop on Revival of Dynamic Languages (2005)

    Google Scholar 

  27. Minamide, Y., Garrigue, J.: On the runtime complexity of type-directed unboxing. In: Proceedings of the ACM SIGPLAN International Conference on Functional Programming (ICFP), pp. 1–12 (1998)

    Chapter  Google Scholar 

  28. Ou, X., Tan, G., Mandelbaum, Y., Walker, D.: Dynamic typing with dependent types. In: Proceedings of the IFIP International Conference on Theoretical Computer Science, pp. 437–450 (2004)

    Google Scholar 

  29. Pil, M.: First class file I/O. In: IFL ’96: Selected Papers from the 8th International Workshop on Implementation of Functional Languages, pp. 233–246, London, UK. Springer, Berlin (1997). ISBN 3-540-63237-9

    Google Scholar 

  30. Siek, J., Wadler, P.: Exploring the design space of higher-order casts. In: Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL) (2010)

    Google Scholar 

  31. Siek, J., Garcia, R., Taha, W.: Exploring the design space of higher-order casts. In: Proceedings of the European Symposium on Programming Languages and Systems (ESOP), pp. 17–31. Springer, Berlin (2009)

    Chapter  Google Scholar 

  32. Siek, J.G., Taha, W.: Gradual typing for functional languages. In: Scheme and Functional Programming Workshop, September 2006

    Google Scholar 

  33. Siek, J.G., Taha, W.: Gradual typing for objects. In: Proceedings of the European Conference on Object-Oriented Programming (ECOOP), Berlin, Germany, July 2007

    Google Scholar 

  34. Tobin-Hochstadt, S., Felleisen, M.: Interlanguage migration: From scripts to programs. In: Dynamic Languages Symposium, October 2006

    Google Scholar 

  35. Tobin-Hochstadt, S., Felleisen, M.: The design and implementation of typed scheme. In: Proceedings of the ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (POPL), pp. 395–406 (2008)

    Google Scholar 

  36. Wallach, D.S.: A New Approach to Mobile Code Security. PhD thesis, Princeton University, Department of Computer Science (1999)

  37. Wright, A.K.: Practical Soft Typing. PhD thesis, Rice University (August 1998)

  38. Xu, D.N., Peyton Jones, S.L., Claessen, K.: Static contract checking for Haskell. In: POPL, pp. 41–52 (2009)

    Google Scholar 

Download references

Author information

Authors and Affiliations

Authors

Corresponding author

Correspondence to David Herman.

Additional information

David Herman was supported by a grant from the Mozilla Corporation. Cormac Flanagan was supported by a Sloan Fellowship and by NSF grant CCS-0341179. Aaron Tomb was also supported by NSF grant CCS-0341179. For Herman, most of this work was done at Northeastern University, Boston, MA.

Rights and permissions

Reprints and permissions

About this article

Cite this article

Herman, D., Tomb, A. & Flanagan, C. Space-efficient gradual typing. Higher-Order Symb Comput 23, 167–189 (2010). https://doi.org/10.1007/s10990-011-9066-z

Download citation

  • Published:

  • Issue Date:

  • DOI: https://doi.org/10.1007/s10990-011-9066-z

Keywords

Navigation