一种面向多阶段编程跨阶段类型抽象的ml风格模块系统

IF 1.4 4区 计算机科学 Q3 COMPUTER SCIENCE, SOFTWARE ENGINEERING
Takashi Suwa , Atsushi Igarashi
{"title":"一种面向多阶段编程跨阶段类型抽象的ml风格模块系统","authors":"Takashi Suwa ,&nbsp;Atsushi Igarashi","doi":"10.1016/j.scico.2025.103379","DOIUrl":null,"url":null,"abstract":"<div><div>We propose <em>MetaFM</em>, a novel ML-style module system that enables users to decompose <em>multi-stage programs</em> (i.e., programs written in a typed <em>multi-stage programming</em> language) into loosely coupled components in a manner natural with respect to type abstraction. The distinctive aspect of MetaFM is that it allows values at different stages to be bound in a single structure (i.e., <span><math><mrow><mi>struct</mi></mrow><mspace></mspace><mo>⋯</mo><mspace></mspace><mrow><mi>end</mi></mrow></math></span>). This feature is crucial, for example, for defining a function and a macro that use one abstract type in common without revealing the implementation detail of that type. MetaFM also accommodates staging with full-fledged module-related features such as <em>functors</em>, <em>higher-kinded types</em>, and the <strong>with type</strong><em>-construct</em>. We give two separate formalizations of MetaFM's semantics by employing the technique of <em>elaborations</em>, i.e., type-directed translations to target languages. Specifically, we first define <em>F-ing Modules</em>-based semantics as a set of elaboration rules that convert MetaFM programs into <em>System F</em><span><math><msup><mrow><mi>ω</mi></mrow><mrow><mo>〈</mo><mo>〉</mo></mrow></msup></math></span>, a multi-stage extension of System F<em>ω</em>, and prove that the elaboration preserves typing. The existential quantification offered by System F<span><math><msup><mrow><mi>ω</mi></mrow><mrow><mo>〈</mo><mo>〉</mo></mrow></msup></math></span> demonstrates that a type abstraction mechanism is properly formalized in our language. Then, because our F-ing Modules-based semantics of staging has some issues as to the evaluation order, we give another elaboration by utilizing a method called <em>static interpretation</em>, which flattens nested structures into arrays of bindings and inlines functor applications through type-checking. While our F-ing Modules-based semantics cannot be naturally extended with effectful computations, the static interpretation-based one can easily accommodate effectful features such as mutable references, though this is achieved with the limitation that functors must be first-order for the moment. As a sideline, we develop a technique that simplifies the correctness proof of the static interpretation for first-order functors. Additionally, our language supports <em>cross-stage persistence</em> (<em>CSP</em>), a feature for code reuse spanning more than one stage, without breaking type safety. We also implemented a module system for a language of real-world use based on the latter semantics to demonstrate the utility of our formalization.</div></div>","PeriodicalId":49561,"journal":{"name":"Science of Computer Programming","volume":"248 ","pages":"Article 103379"},"PeriodicalIF":1.4000,"publicationDate":"2025-08-11","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":"{\"title\":\"An ML-style module system for cross-stage type abstraction in multi-stage programming\",\"authors\":\"Takashi Suwa ,&nbsp;Atsushi Igarashi\",\"doi\":\"10.1016/j.scico.2025.103379\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"<div><div>We propose <em>MetaFM</em>, a novel ML-style module system that enables users to decompose <em>multi-stage programs</em> (i.e., programs written in a typed <em>multi-stage programming</em> language) into loosely coupled components in a manner natural with respect to type abstraction. The distinctive aspect of MetaFM is that it allows values at different stages to be bound in a single structure (i.e., <span><math><mrow><mi>struct</mi></mrow><mspace></mspace><mo>⋯</mo><mspace></mspace><mrow><mi>end</mi></mrow></math></span>). This feature is crucial, for example, for defining a function and a macro that use one abstract type in common without revealing the implementation detail of that type. MetaFM also accommodates staging with full-fledged module-related features such as <em>functors</em>, <em>higher-kinded types</em>, and the <strong>with type</strong><em>-construct</em>. We give two separate formalizations of MetaFM's semantics by employing the technique of <em>elaborations</em>, i.e., type-directed translations to target languages. Specifically, we first define <em>F-ing Modules</em>-based semantics as a set of elaboration rules that convert MetaFM programs into <em>System F</em><span><math><msup><mrow><mi>ω</mi></mrow><mrow><mo>〈</mo><mo>〉</mo></mrow></msup></math></span>, a multi-stage extension of System F<em>ω</em>, and prove that the elaboration preserves typing. The existential quantification offered by System F<span><math><msup><mrow><mi>ω</mi></mrow><mrow><mo>〈</mo><mo>〉</mo></mrow></msup></math></span> demonstrates that a type abstraction mechanism is properly formalized in our language. Then, because our F-ing Modules-based semantics of staging has some issues as to the evaluation order, we give another elaboration by utilizing a method called <em>static interpretation</em>, which flattens nested structures into arrays of bindings and inlines functor applications through type-checking. While our F-ing Modules-based semantics cannot be naturally extended with effectful computations, the static interpretation-based one can easily accommodate effectful features such as mutable references, though this is achieved with the limitation that functors must be first-order for the moment. As a sideline, we develop a technique that simplifies the correctness proof of the static interpretation for first-order functors. Additionally, our language supports <em>cross-stage persistence</em> (<em>CSP</em>), a feature for code reuse spanning more than one stage, without breaking type safety. We also implemented a module system for a language of real-world use based on the latter semantics to demonstrate the utility of our formalization.</div></div>\",\"PeriodicalId\":49561,\"journal\":{\"name\":\"Science of Computer Programming\",\"volume\":\"248 \",\"pages\":\"Article 103379\"},\"PeriodicalIF\":1.4000,\"publicationDate\":\"2025-08-11\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"0\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Science of Computer Programming\",\"FirstCategoryId\":\"94\",\"ListUrlMain\":\"https://www.sciencedirect.com/science/article/pii/S0167642325001182\",\"RegionNum\":4,\"RegionCategory\":\"计算机科学\",\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"Q3\",\"JCRName\":\"COMPUTER SCIENCE, SOFTWARE ENGINEERING\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Science of Computer Programming","FirstCategoryId":"94","ListUrlMain":"https://www.sciencedirect.com/science/article/pii/S0167642325001182","RegionNum":4,"RegionCategory":"计算机科学","ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"Q3","JCRName":"COMPUTER SCIENCE, SOFTWARE ENGINEERING","Score":null,"Total":0}
引用次数: 0

摘要

我们提出了MetaFM,一个新颖的ml风格的模块系统,它使用户能够将多阶段程序(即,用类型化的多阶段编程语言编写的程序)以一种与类型抽象相关的自然方式分解成松散耦合的组件。MetaFM的独特之处在于,它允许将不同阶段的值绑定在单个结构中(即struct⋯end)。例如,对于定义一个共用一个抽象类型的函数和宏,而不透露该类型的实现细节,这个特性是至关重要的。MetaFM还支持与成熟的模块相关的特性,如函子、高级类型和with类型构造。我们通过使用精化技术,即向目标语言进行类型导向翻译,给出了MetaFM语义的两种独立形式化形式。具体来说,我们首先将基于F-ing模块的语义定义为一组精化规则,该规则将MetaFM程序转换为System Fω < > (System Fω的多阶段扩展),并证明精化保留了类型化。System Fω < >提供的存在量化表明,在我们的语言中,类型抽象机制是正确形式化的。然后,由于我们的基于F-ing模块的分段语义在求值顺序方面存在一些问题,我们通过使用一种称为静态解释的方法进行了另一种阐述,该方法通过类型检查将嵌套结构扁平化为绑定数组和内联函子应用程序。虽然我们基于F-ing模块的语义不能自然地扩展为有效的计算,但基于静态解释的语义可以很容易地容纳有效的特性,如可变引用,尽管这是通过限制函子目前必须是一阶的来实现的。作为副业,我们开发了一种简化一阶函子静态解释正确性证明的技术。此外,我们的语言支持跨阶段持久性(CSP),这是一种跨多个阶段的代码重用功能,而不会破坏类型安全。我们还为基于后一种语义的实际使用的语言实现了一个模块系统,以演示我们的形式化的实用性。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
An ML-style module system for cross-stage type abstraction in multi-stage programming
We propose MetaFM, a novel ML-style module system that enables users to decompose multi-stage programs (i.e., programs written in a typed multi-stage programming language) into loosely coupled components in a manner natural with respect to type abstraction. The distinctive aspect of MetaFM is that it allows values at different stages to be bound in a single structure (i.e., structend). This feature is crucial, for example, for defining a function and a macro that use one abstract type in common without revealing the implementation detail of that type. MetaFM also accommodates staging with full-fledged module-related features such as functors, higher-kinded types, and the with type-construct. We give two separate formalizations of MetaFM's semantics by employing the technique of elaborations, i.e., type-directed translations to target languages. Specifically, we first define F-ing Modules-based semantics as a set of elaboration rules that convert MetaFM programs into System Fω, a multi-stage extension of System Fω, and prove that the elaboration preserves typing. The existential quantification offered by System Fω demonstrates that a type abstraction mechanism is properly formalized in our language. Then, because our F-ing Modules-based semantics of staging has some issues as to the evaluation order, we give another elaboration by utilizing a method called static interpretation, which flattens nested structures into arrays of bindings and inlines functor applications through type-checking. While our F-ing Modules-based semantics cannot be naturally extended with effectful computations, the static interpretation-based one can easily accommodate effectful features such as mutable references, though this is achieved with the limitation that functors must be first-order for the moment. As a sideline, we develop a technique that simplifies the correctness proof of the static interpretation for first-order functors. Additionally, our language supports cross-stage persistence (CSP), a feature for code reuse spanning more than one stage, without breaking type safety. We also implemented a module system for a language of real-world use based on the latter semantics to demonstrate the utility of our formalization.
求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
Science of Computer Programming
Science of Computer Programming 工程技术-计算机:软件工程
CiteScore
3.80
自引率
0.00%
发文量
76
审稿时长
67 days
期刊介绍: Science of Computer Programming is dedicated to the distribution of research results in the areas of software systems development, use and maintenance, including the software aspects of hardware design. The journal has a wide scope ranging from the many facets of methodological foundations to the details of technical issues andthe aspects of industrial practice. The subjects of interest to SCP cover the entire spectrum of methods for the entire life cycle of software systems, including • Requirements, specification, design, validation, verification, coding, testing, maintenance, metrics and renovation of software; • Design, implementation and evaluation of programming languages; • Programming environments, development tools, visualisation and animation; • Management of the development process; • Human factors in software, software for social interaction, software for social computing; • Cyber physical systems, and software for the interaction between the physical and the machine; • Software aspects of infrastructure services, system administration, and network management.
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
确定
请完成安全验证×
copy
已复制链接
快去分享给好友吧!
我知道了
右上角分享
点击右上角分享
0
联系我们:info@booksci.cn Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。 Copyright © 2023 布克学术 All rights reserved.
京ICP备2023020795号-1
ghs 京公网安备 11010802042870号
Book学术文献互助
Book学术文献互助群
群 号:604180095
Book学术官方微信