Programmable semantic fragments: the design and implementation of typy
-
Published:2017-05-12
Issue:3
Volume:52
Page:81-92
-
ISSN:0362-1340
-
Container-title:ACM SIGPLAN Notices
-
language:en
-
Short-container-title:SIGPLAN Not.
Author:
Omar Cyrus1,
Aldrich Jonathan1
Affiliation:
1. Carnegie Mellon University, USA
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.)
Funder
Defense Advanced Research Projects Agency
National Security Agency
Publisher
Association for Computing Machinery (ACM)
Subject
Computer Graphics and Computer-Aided Design,Software
Reference74 articles.
1. Flow — A static type checker for JavaScript. http:// flowtype.org/. 1 Flow — A static type checker for JavaScript. http:// flowtype.org/. 1
2. PEP 3107 – Function Annotations. https://www.python. org/dev/peps/pep-3107/. 2.1 PEP 3107 – Function Annotations. https://www.python. org/dev/peps/pep-3107/. 2.1
3. PureScript. http://www.purescript.org/. 1 PureScript. http://www.purescript.org/. 1
4. Towards the Essence of Hygiene