skip to main content
article
Public Access

Programmable semantic fragments: the design and implementation of typy

Published:20 October 2016Publication History
Skip Abstract Section

Abstract

This paper introduces typy, a statically typed programming language embedded by reflection into Python. typy features a fragmentary semantics, i.e. it delegates semantic control over each term, drawn from Python's fixed concrete and abstract syntax, to some contextually relevant user-defined semantic fragment. The delegated fragment programmatically 1) typechecks the term (following a bidirectional protocol); and 2) assigns dynamic meaning to the term by computing a translation to Python.

We argue that this design is expressive with examples of fragments that express the static and dynamic semantics of 1) functional records; 2) labeled sums (with nested pattern matching a la ML); 3) a variation on JavaScript's prototypal object system; and 4) typed foreign interfaces to Python and OpenCL. These semantic structures are, or would need to be, defined primitively in conventionally structured languages.

We further argue that this design is compositionally well-behaved. It avoids the expression problem and the problems of grammar composition because the syntax is fixed. Moreover, programs are semantically stable under fragment composition (i.e. defining a new fragment will not change the meaning of existing program components.)

References

  1. Flow — A static type checker for JavaScript. http:// flowtype.org/. 1Google ScholarGoogle Scholar
  2. PEP 3107 – Function Annotations. https://www.python. org/dev/peps/pep-3107/. 2.1Google ScholarGoogle Scholar
  3. PureScript. http://www.purescript.org/. 1Google ScholarGoogle Scholar
  4. The OpenCL Specification, Version 1.1, 2010. 3.2Google ScholarGoogle Scholar
  5. M. D. Adams. Towards the Essence of Hygiene. In POPL, 2015. 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  6. D. Ancona, M. Ancona, A. Cuni, and N. D. Matsakis. RPython: a step towards reconciling dynamically and statically typed OO languages. In Symposium on Dynamic Languages, 2007. 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. C. Andreae, J. Noble, S. Markstrum, and T. Millstein. A Framework for Implementing Pluggable Type Systems. In OOPSLA, 2006. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  8. B. E. Aydemir, A. Bohannon, M. Fairbairn, J. N. Foster, B. C. Pierce, P. Sewell, D. Vytiniotis, G. Washburn, S. Weirich, and S. Zdancewic. Mechanized Metatheory for the Masses: The POPLmark Challenge. In Theorem Proving in Higher Order Logics: 18th International Conference, 2005. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  9. D. M. Beazley. Automated scientific software scripting with SWIG. Future Generation Computer Systems, 19(5):599–609, 2003. 3.2 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. N. Benton and A. Kennedy. Interlanguage Working Without Tears: Blending SML with Java. In ICFP, 1999. 3.2 Google ScholarGoogle ScholarDigital LibraryDigital Library
  11. G. Bierman, M. Abadi, and M. Torgersen. Understanding TypeScript. In ECOOP. 2014. 1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  12. G. Bracha. Pluggable Type Systems. In OOPSLA Workshop on Revival of Dynamic Languages, 2004. 4Google ScholarGoogle Scholar
  13. F. Brown, A. Nötzli, and D. Engler. How to Build Static Checking Systems Using Orders of Magnitude Less Code. In ASPLOS, 2016. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. E. Burmako. Scala Macros: Let Our Powers Combine!: On How Rich Syntax and Static Types Work with Metaprogramming. In 4th Workshop on Scala, 2013. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. A. Chlipala. A verified compiler for an impure functional language. In POPL, 2010. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. D. R. Christiansen. Bidirectional Typing Rules: A Tutorial. http://davidchristiansen.dk/tutorials/ bidirectional.pdf, 2013. 2.3Google ScholarGoogle Scholar
  17. R. Cox, T. Bergan, A. T. Clements, M. F. Kaashoek, and E. Kohler. Xoc, an extension-oriented compiler for systems programming. In ASPLOS, 2008. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. K. Crary. A syntactic account of singleton types via hereditary substitution. In Fourth International Workshop on Logical Frameworks and Meta-Languages: Theory and Practice (LFMTP), 2009. 2.2, 2.5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. R. Culpepper, S. Tobin-Hochstadt, and M. Flatt. Advanced macrology and the implementation of Typed Scheme. In Workshop on Scheme and Functional Programming, 2007. 4Google ScholarGoogle Scholar
  20. B. Delaware, W. R. Cook, and D. S. Batory. Product lines of theorems. In OOPSLA, 2011. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. B. Delaware, B. C. d. S. Oliveira, and T. Schrijvers. Metatheory à la carte. In POPL, 2013. 4Google ScholarGoogle Scholar
  22. F. DeRemer and H. Kron. Programming-in-the-large versus programming-in-the-small. IEEE Transactions on Software Engineering, 2:80–86, 1976. 1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. J. Dunfield and N. R. Krishnaswami. Complete and easy bidirectional typechecking for higher-rank polymorphism. In ICFP, 2013. 2.3, 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. T. Ekman and G. Hedin. The JastAdd extensible Java compiler. In OOPSLA, 2007. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. S. Erdweg and F. Rieger. A framework for extensible languages. In GPCE, 2013. 1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  26. S. Erdweg, T. van der Storm, M. Völter, M. Boersma, R. Bosman, W. R. Cook, A. Gerritsen, A. Hulshout, S. Kelly, A. Loh, G. D. P. Konat, P. J. Molina, M. Palatnik, R. Pohjonen, E. Schindler, K. Schindler, R. Solmi, V. A. Vergu, E. Visser, K. van der Vlist, G. H. Wachsmuth, and J. van der Woning. The state of the art in language workbenches. In Software Language Engineering (SLE). 2013. 4Google ScholarGoogle Scholar
  27. M. Felleisen, R. B. Findler, and M. Flatt. Semantics Engineering with PLT Redex. The MIT Press, 2009. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. D. Fisher and O. Shivers. Building language towers with Ziggurat. J. Funct. Program., 18(5-6):707–780, 2008. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. M. Flatt. Creating languages in Racket. Commun. ACM, 55(1):48–56, Jan. 2012. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. M. Flatt, R. Culpepper, D. Darais, and R. B. Findler. Macros that work together - compile-time bindings, partial expansion, and definition contexts. J. Funct. Program., 22(2):181–216, 2012. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  31. T. Freeman and F. Pfenning. Refinement Types for ML. In PLDI, 1991. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  32. N. Fulton, C. Omar, and J. Aldrich. Statically Typed String Sanitation Inside a Python. In International Workshop on Privacy and Security in Programming (PSP), 2014. 2.3.1, 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. S. Grewe, S. Erdweg, P. Wittmann, and M. Mezini. Type systems for the masses: Deriving soundness proofs and efficient checkers. In ACM International Symposium on New Ideas, New Paradigms, and Reflections on Programming and Software (Onward!), 2015. 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  34. R. Harper. Practical Foundations for Programming Languages. Cambridge University Press, 2nd edition, 2016. 2.2, 2.3.1, 2.4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  35. T. P. Hart. MACRO definitions for LISP. Report A. I. MEMO 57, Massachusetts Institute of Technology, A.I. Lab., Cambridge, Massachusetts, Oct. 1963. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. S. P. Jones. Haskell 98 language and libraries: the revised report. Cambridge University Press, 2003. 2.4Google ScholarGoogle Scholar
  37. G. Kiczales, J. des Rivières, and D. G. Bobrow. The Art of the Metaobject Protocol. MIT Press, Cambridge, MA, 1991. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. A. Klöckner, N. Pinto, Y. Lee, B. Catanzaro, P. Ivanov, and A. Fasih. PyCUDA and PyOpenCL: A Scripting-Based Approach to GPU Run-Time Code Generation. Parallel Computing, 2011. 1, 3.2Google ScholarGoogle Scholar
  39. E. E. Kohlbecker, D. P. Friedman, M. Felleisen, and B. Duba. Hygienic macro expansion. In Symposium on LISP and Functional Programming, pages 151–161, Aug. 1986. 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. J. Lehtosalo. mypy - Optional Static Typing for Python. http://www.mypy-lang.org/. Retrieved June 24, 2016. 4Google ScholarGoogle Scholar
  41. B. S. Lerner, J. G. Politz, A. Guha, and S. Krishnamurthi. TeJaS: retrofitting type systems for JavaScript. In Dynamic Languages Symposium (DLS), 2013. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  42. X. Leroy, D. Doligez, A. Frisch, J. Garrigue, D. Rémy, and J. Vouillon. The OCaml system release 4.02 Documentation and user’s manual. Institut National de Recherche en Informatique et en Automatique, September 2014. 2.4Google ScholarGoogle Scholar
  43. M. Y. Levin and B. C. Pierce. TinkerType: A Language for Playing with Formal Systems. Journal of Functional Programming, 13(2), Mar. 2003. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. H. Lieberman. Using Prototypical Objects to Implement Shared Behavior in Object Oriented Systems. In OOPSLA, 1986. 3.1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. S. Markstrum, D. Marino, M. Esquivel, T. D. Millstein, C. Andreae, and J. Noble. JavaCOP: Declarative pluggable types for Java. ACM Trans. Program. Lang. Syst., 32(2), 2010. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. J. Matthews and R. B. Findler. Operational semantics for multilanguage programs. ACM Trans. Program. Lang. Syst., 31(3), 2009. 1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. The Coq development team. The Coq proof assistant reference manual. LogiCal Project, 2004. Version 8.0. 4Google ScholarGoogle Scholar
  48. R. Milner. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17(3):348–375, 1978. 1Google ScholarGoogle ScholarCross RefCross Ref
  49. U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology, 2007. 4, 5Google ScholarGoogle Scholar
  50. N. Nystrom, M. R. Clarkson, and A. C. Myers. Polyglot: An Extensible Compiler Framework for Java. In Compiler Construction: 12th International Conference, 2003. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  51. M. Odersky, M. Zenger, and C. Zenger. Colored Local Type Inference. In POPL, 2001. 2.3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  52. T. E. Oliphant. Python for scientific computing. Computing in Science & Engineering, 9(3):10–20, 2007. 3.2 Google ScholarGoogle ScholarDigital LibraryDigital Library
  53. B. C. d. S. Oliveira and W. R. Cook. Extensibility for the masses. In ECOOP. Springer, 2012. 4Google ScholarGoogle ScholarDigital LibraryDigital Library
  54. C. Omar and J. Aldrich. Programmable Semantic Fragments (Extended Version). Technical Report CMU-ISR-16-112, Carnegie Mellon University. 2.1, 2.3.1, 7, 2.4Google ScholarGoogle Scholar
  55. C. Omar, D. Kurilova, L. Nistor, B. Chung, A. Potanin, and J. Aldrich. Safely composable type-specific languages. In ECOOP, 2014. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  56. B. C. Pierce and D. N. Turner. Local type inference. ACM Trans. Program. Lang. Syst., 22(1):1–44, Jan. 2000. 2.3 Google ScholarGoogle ScholarDigital LibraryDigital Library
  57. J. G. Politz, A. Martinez, M. Milano, S. Warren, D. Patterson, J. Li, A. Chitipothu, and S. Krishnamurthi. Python: the full monty. In OOPSLA, 2013. 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  58. J. Rafkind and M. Flatt. Honu: syntactic extension for algebraic notation through enforestation. In Generative Programming and Component Engineering, GPCE’12, Dresden, Germany, September 26-28, 2012, pages 122–131, 2012. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  59. J. C. Reynolds. User-defined types and procedural data structures as complementary approaches to data abstraction. In Conference on New Directions on Algorithmic Languages, Aug. 1975. 1, 4Google ScholarGoogle Scholar
  60. T. Rompf and M. Odersky. Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs. Communications of the ACM, 55(6):121–130, June 2012. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  61. C. Schwaab and J. G. Siek. Modular type-safety proofs in Agda. In Workshop on Programming Languages Meets Program Verification (PLPV), 2013. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  62. A. Schwerdfeger and E. V. Wyk. Verifiable composition of deterministic grammars. In PLDI ’09, pages 199–210, 2009. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  63. D. Scott. Lambda calculus: some models, some philosophy. Studies in Logic and the Foundations of Mathematics, 101:223– 265, 1980. 2.3.1Google ScholarGoogle ScholarCross RefCross Ref
  64. J. Siek and W. Taha. Gradual typing for objects. In ECOOP, 2007. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  65. J. G. Siek and W. Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, 2006. 4Google ScholarGoogle Scholar
  66. D. Tarditi, G. Morrisett, P. Cheng, C. Stone, R. Harper, and P. Lee. TIL: A Type-Directed Optimizing Compiler for ML. In PLDI, 1996. 5 Google ScholarGoogle ScholarDigital LibraryDigital Library
  67. S. Tobin-Hochstadt and M. Felleisen. The Design and Implementation of Typed Scheme. In POPL, 2008. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  68. L. Tratt. Domain specific language implementation via compile-time meta-programming. ACM Trans. Program. Lang. Syst., 30(6), 2008. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  69. D. Unger and R. B. Smith. Self: The Power of Simplicity. In OOPSLA, pages 227–242, Dec. 1987. 3.1 Google ScholarGoogle ScholarDigital LibraryDigital Library
  70. S. Van Der Walt, S. C. Colbert, and G. Varoquaux. The numpy array: a structure for efficient numerical computation. Computing in Science & Engineering, 13(2):22–30, 2011. 3.2 Google ScholarGoogle ScholarDigital LibraryDigital Library
  71. A. van Wijngaarden, B. J. Mailloux, J. E. Peck, C. H. A. Koster, M. Sintzoff, C. H. Lindsey, L. G. L. T. Meertens, and R. G. Fisker. Revised Report on the Algorithmic Language Algol 68. Acta Informatica, 1975. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  72. E. Van Wyk, D. Bodin, J. Gao, and L. Krishnan. Silver: an extensible attribute grammar system. Science of Computer Programming, 75(1–2):39–54, Jan. 2010. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  73. M. M. Vitousek, A. M. Kent, J. G. Siek, and J. Baker. Design and evaluation of gradual typing for Python. In Dynamic Languages Symposium, 2014. 4 Google ScholarGoogle ScholarDigital LibraryDigital Library
  74. P. Wadler. The expression problem. java-genericity mailing list, 1998. 1, 4Google ScholarGoogle Scholar
  75. M. P. Ward. Language-oriented programming. Software - Concepts and Tools, 15(4):147–161, 1994. 1Google ScholarGoogle Scholar

Index Terms

  1. Programmable semantic fragments: the design and implementation of typy

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!