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.)
- Flow — A static type checker for JavaScript. http:// flowtype.org/. 1Google Scholar
- PEP 3107 – Function Annotations. https://www.python. org/dev/peps/pep-3107/. 2.1Google Scholar
- PureScript. http://www.purescript.org/. 1Google Scholar
- The OpenCL Specification, Version 1.1, 2010. 3.2Google Scholar
- M. D. Adams. Towards the Essence of Hygiene. In POPL, 2015. 5 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- C. Andreae, J. Noble, S. Markstrum, and T. Millstein. A Framework for Implementing Pluggable Type Systems. In OOPSLA, 2006. 4 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- D. M. Beazley. Automated scientific software scripting with SWIG. Future Generation Computer Systems, 19(5):599–609, 2003. 3.2 Google Scholar
Digital Library
- N. Benton and A. Kennedy. Interlanguage Working Without Tears: Blending SML with Java. In ICFP, 1999. 3.2 Google Scholar
Digital Library
- G. Bierman, M. Abadi, and M. Torgersen. Understanding TypeScript. In ECOOP. 2014. 1 Google Scholar
Digital Library
- G. Bracha. Pluggable Type Systems. In OOPSLA Workshop on Revival of Dynamic Languages, 2004. 4Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- A. Chlipala. A verified compiler for an impure functional language. In POPL, 2010. 4 Google Scholar
Digital Library
- D. R. Christiansen. Bidirectional Typing Rules: A Tutorial. http://davidchristiansen.dk/tutorials/ bidirectional.pdf, 2013. 2.3Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- B. Delaware, W. R. Cook, and D. S. Batory. Product lines of theorems. In OOPSLA, 2011. 4 Google Scholar
Digital Library
- B. Delaware, B. C. d. S. Oliveira, and T. Schrijvers. Metatheory à la carte. In POPL, 2013. 4Google Scholar
- 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 Scholar
Digital Library
- J. Dunfield and N. R. Krishnaswami. Complete and easy bidirectional typechecking for higher-rank polymorphism. In ICFP, 2013. 2.3, 5 Google Scholar
Digital Library
- T. Ekman and G. Hedin. The JastAdd extensible Java compiler. In OOPSLA, 2007. 4 Google Scholar
Digital Library
- S. Erdweg and F. Rieger. A framework for extensible languages. In GPCE, 2013. 1 Google Scholar
Digital Library
- 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 Scholar
- M. Felleisen, R. B. Findler, and M. Flatt. Semantics Engineering with PLT Redex. The MIT Press, 2009. 4 Google Scholar
Digital Library
- D. Fisher and O. Shivers. Building language towers with Ziggurat. J. Funct. Program., 18(5-6):707–780, 2008. 4 Google Scholar
Digital Library
- M. Flatt. Creating languages in Racket. Commun. ACM, 55(1):48–56, Jan. 2012. 4 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- T. Freeman and F. Pfenning. Refinement Types for ML. In PLDI, 1991. 4 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- R. Harper. Practical Foundations for Programming Languages. Cambridge University Press, 2nd edition, 2016. 2.2, 2.3.1, 2.4 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- S. P. Jones. Haskell 98 language and libraries: the revised report. Cambridge University Press, 2003. 2.4Google Scholar
- G. Kiczales, J. des Rivières, and D. G. Bobrow. The Art of the Metaobject Protocol. MIT Press, Cambridge, MA, 1991. 4 Google Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- J. Lehtosalo. mypy - Optional Static Typing for Python. http://www.mypy-lang.org/. Retrieved June 24, 2016. 4Google Scholar
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- H. Lieberman. Using Prototypical Objects to Implement Shared Behavior in Object Oriented Systems. In OOPSLA, 1986. 3.1 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- J. Matthews and R. B. Findler. Operational semantics for multilanguage programs. ACM Trans. Program. Lang. Syst., 31(3), 2009. 1 Google Scholar
Digital Library
- The Coq development team. The Coq proof assistant reference manual. LogiCal Project, 2004. Version 8.0. 4Google Scholar
- R. Milner. A theory of type polymorphism in programming. J. Comput. Syst. Sci., 17(3):348–375, 1978. 1Google Scholar
Cross Ref
- U. Norell. Towards a practical programming language based on dependent type theory. PhD thesis, Chalmers University of Technology, 2007. 4, 5Google Scholar
- 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 Scholar
Digital Library
- M. Odersky, M. Zenger, and C. Zenger. Colored Local Type Inference. In POPL, 2001. 2.3 Google Scholar
Digital Library
- T. E. Oliphant. Python for scientific computing. Computing in Science & Engineering, 9(3):10–20, 2007. 3.2 Google Scholar
Digital Library
- B. C. d. S. Oliveira and W. R. Cook. Extensibility for the masses. In ECOOP. Springer, 2012. 4Google Scholar
Digital Library
- 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 Scholar
- C. Omar, D. Kurilova, L. Nistor, B. Chung, A. Potanin, and J. Aldrich. Safely composable type-specific languages. In ECOOP, 2014. 4 Google Scholar
Digital Library
- B. C. Pierce and D. N. Turner. Local type inference. ACM Trans. Program. Lang. Syst., 22(1):1–44, Jan. 2000. 2.3 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
- 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 Scholar
Digital Library
- C. Schwaab and J. G. Siek. Modular type-safety proofs in Agda. In Workshop on Programming Languages Meets Program Verification (PLPV), 2013. 4 Google Scholar
Digital Library
- A. Schwerdfeger and E. V. Wyk. Verifiable composition of deterministic grammars. In PLDI ’09, pages 199–210, 2009. 4 Google Scholar
Digital Library
- D. Scott. Lambda calculus: some models, some philosophy. Studies in Logic and the Foundations of Mathematics, 101:223– 265, 1980. 2.3.1Google Scholar
Cross Ref
- J. Siek and W. Taha. Gradual typing for objects. In ECOOP, 2007. 4 Google Scholar
Digital Library
- J. G. Siek and W. Taha. Gradual typing for functional languages. In Scheme and Functional Programming Workshop, 2006. 4Google Scholar
- 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 Scholar
Digital Library
- S. Tobin-Hochstadt and M. Felleisen. The Design and Implementation of Typed Scheme. In POPL, 2008. 4 Google Scholar
Digital Library
- L. Tratt. Domain specific language implementation via compile-time meta-programming. ACM Trans. Program. Lang. Syst., 30(6), 2008. 4 Google Scholar
Digital Library
- D. Unger and R. B. Smith. Self: The Power of Simplicity. In OOPSLA, pages 227–242, Dec. 1987. 3.1 Google Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- 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 Scholar
Digital Library
- P. Wadler. The expression problem. java-genericity mailing list, 1998. 1, 4Google Scholar
- M. P. Ward. Language-oriented programming. Software - Concepts and Tools, 15(4):147–161, 1994. 1Google Scholar
Index Terms
Programmable semantic fragments: the design and implementation of typy
Recommendations
Programmable semantic fragments: the design and implementation of typy
GPCE 2016: Proceedings of the 2016 ACM SIGPLAN International Conference on Generative Programming: Concepts and ExperiencesThis 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 ...
Safely Composable Type-Specific Languages
Proceedings of the 28th European Conference on ECOOP 2014 --- Object-Oriented Programming - Volume 8586Programming languages often include specialized syntax for common datatypes e.g. lists and some also build in support for specific specialized datatypes e.g. regular expressions, but user-defined types must use general-purpose syntax. Frustration with ...
Sound type-dependent syntactic language extension
POPL '16: Proceedings of the 43rd Annual ACM SIGPLAN-SIGACT Symposium on Principles of Programming LanguagesSyntactic language extensions can introduce new facilities into a programming language while requiring little implementation effort and modest changes to the compiler. It is typical to desugar language extensions in a distinguished compiler phase after ...







Comments