{"title":"Blame and coercion: Together again for the first time","authors":"JEREMY G. SIEK, PETER THIEMANN, PHILIP WADLER","doi":"10.1017/s0956796821000101","DOIUrl":null,"url":null,"abstract":"C#, Dart, Pyret, Racket, TypeScript, VB: many recent languages integrate dynamic and static types via gradual typing. We systematically develop four calculi for gradual typing and the relations between them, building on and strengthening previous work. The calculi are as follows: <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline1.png\" /> <jats:tex-math> $\\lambda{B}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, based on the blame calculus of Wadler and Findler (2009); <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline2.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, inspired by the coercion calculus of Henglein (1994); <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline3.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> inspired by the space-efficient calculus of Herman, Tomb, and Flanagan (2006); and <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline4.png\" /> <jats:tex-math> $\\lambda{T}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> based on the threesome calculus of Siek and Wadler (2010). While <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline5.png\" /> <jats:tex-math> $\\lambda{B}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> and <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline6.png\" /> <jats:tex-math> $\\lambda{T}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> are little changed from previous work, <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline7.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> and <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline8.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> are new. Together, <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline9.png\" /> <jats:tex-math> $\\lambda{B}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline10.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline11.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, and <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline12.png\" /> <jats:tex-math> $\\lambda{T}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> provide a coherent foundation for design, implementation, and optimization of gradual types. We define translations from <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline13.png\" /> <jats:tex-math> $\\lambda{B}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> to <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline14.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, from <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline15.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> to <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline16.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>, and from <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline17.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> to <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline18.png\" /> <jats:tex-math> $\\lambda{T}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>. Much previous work lacked proofs of correctness or had weak correctness criteria; here we demonstrate the strongest correctness criterion one could hope for, that each of the translations is fully abstract. Each of the calculi reinforces the design of the others: <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline19.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> has a particularly simple definition, and the subtle definition of blame safety for <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline20.png\" /> <jats:tex-math> $\\lambda{B}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> is justified by the simple definition of blame safety for <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline21.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula>. Our calculus <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline22.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> is implementation-ready: the first space-efficient calculus that is both straightforward to implement and easy to understand. We give two applications: first, using full abstraction from <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline23.png\" /> <jats:tex-math> $\\lambda{C}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> to <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline24.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> to establish an equational theory of coercions; and second, using full abstraction from <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline25.png\" /> <jats:tex-math> $\\lambda{B}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> to <jats:inline-formula> <jats:alternatives> <jats:inline-graphic xmlns:xlink=\"http://www.w3.org/1999/xlink\" mime-subtype=\"png\" xlink:href=\"S0956796821000101_inline26.png\" /> <jats:tex-math> $\\lambda{S}$ </jats:tex-math> </jats:alternatives> </jats:inline-formula> to easily establish the Fundamental Property of Casts, which required a custom bisimulation and six lemmas in earlier work.","PeriodicalId":15874,"journal":{"name":"Journal of Functional Programming","volume":"62 1","pages":""},"PeriodicalIF":1.1000,"publicationDate":"2021-10-13","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Journal of Functional Programming","FirstCategoryId":"94","ListUrlMain":"https://doi.org/10.1017/s0956796821000101","RegionNum":3,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q4","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
引用次数: 0
Abstract
C#, Dart, Pyret, Racket, TypeScript, VB: many recent languages integrate dynamic and static types via gradual typing. We systematically develop four calculi for gradual typing and the relations between them, building on and strengthening previous work. The calculi are as follows: $\lambda{B}$ , based on the blame calculus of Wadler and Findler (2009); $\lambda{C}$ , inspired by the coercion calculus of Henglein (1994); $\lambda{S}$ inspired by the space-efficient calculus of Herman, Tomb, and Flanagan (2006); and $\lambda{T}$ based on the threesome calculus of Siek and Wadler (2010). While $\lambda{B}$ and $\lambda{T}$ are little changed from previous work, $\lambda{C}$ and $\lambda{S}$ are new. Together, $\lambda{B}$ , $\lambda{C}$ , $\lambda{S}$ , and $\lambda{T}$ provide a coherent foundation for design, implementation, and optimization of gradual types. We define translations from $\lambda{B}$ to $\lambda{C}$ , from $\lambda{C}$ to $\lambda{S}$ , and from $\lambda{S}$ to $\lambda{T}$ . Much previous work lacked proofs of correctness or had weak correctness criteria; here we demonstrate the strongest correctness criterion one could hope for, that each of the translations is fully abstract. Each of the calculi reinforces the design of the others: $\lambda{C}$ has a particularly simple definition, and the subtle definition of blame safety for $\lambda{B}$ is justified by the simple definition of blame safety for $\lambda{C}$ . Our calculus $\lambda{S}$ is implementation-ready: the first space-efficient calculus that is both straightforward to implement and easy to understand. We give two applications: first, using full abstraction from $\lambda{C}$ to $\lambda{S}$ to establish an equational theory of coercions; and second, using full abstraction from $\lambda{B}$ to $\lambda{S}$ to easily establish the Fundamental Property of Casts, which required a custom bisimulation and six lemmas in earlier work.
c#、Dart、Pyret、Racket、TypeScript、VB:许多最新的语言都通过渐进式类型集成了动态类型和静态类型。在前人工作的基础上,系统地发展了四种渐进式演算及其相互关系。演算公式如下:$\lambda{B}$,基于Wadler and Findler(2009)的责备演算;$\lambda{C}$,灵感来自Henglein(1994)的强制演算;$\lambda{S}$灵感来自Herman, Tomb, and Flanagan(2006)的空间高效演算;和基于Siek和Wadler(2010)的三人微积分的$\lambda{T}$。虽然$\lambda{B}$和$\lambda{T}$与以前的工作相比变化不大,但$\lambda{C}$和$\lambda{S}$是新的。$\lambda{B}$、$\lambda{C}$、$\lambda{S}$和$\lambda{T}$共同为渐变类型的设计、实现和优化提供了一个连贯的基础。我们定义从$\lambda{B}$到$\lambda{C}$的转换,从$\lambda{C}$到$\lambda{S}$的转换,以及从$\lambda{S}$到$\lambda{T}$的转换。许多先前的工作缺乏正确性的证明,或者正确性标准很弱;在这里,我们展示了人们所能期望的最强的正确性标准,即每个翻译都是完全抽象的。每个演算都加强了其他演算的设计:$\lambda{C}$有一个特别简单的定义,$\lambda{B}$的责备安全的微妙定义被$\lambda{C}$的责备安全的简单定义所证明。我们的演算$\lambda{S}$已经为实现做好了准备:这是第一个既易于实现又易于理解的节省空间的演算。我们给出了两个应用:第一,利用$\lambda{C}$到$\lambda{S}$的完全抽象,建立了一个等价的强制子理论;其次,使用从$\lambda{B}$到$\lambda{S}$的完全抽象,可以轻松地建立类型转换的基本属性,这在早期的工作中需要一个自定义的双模拟和六个引理。
期刊介绍:
Journal of Functional Programming is the only journal devoted solely to the design, implementation, and application of functional programming languages, spanning the range from mathematical theory to industrial practice. Topics covered include functional languages and extensions, implementation techniques, reasoning and proof, program transformation and synthesis, type systems, type theory, language-based security, memory management, parallelism and applications. The journal is of interest to computer scientists, software engineers, programming language researchers and mathematicians interested in the logical foundations of programming.