Ornaments: exploiting parametricity for safer, more automated code refactorization and code reuse (invited talk)

Didier Rémy
{"title":"Ornaments: exploiting parametricity for safer, more automated code refactorization and code reuse (invited talk)","authors":"Didier Rémy","doi":"10.1145/3122955.3127333","DOIUrl":null,"url":null,"abstract":"Inductive datatypes and parametric polymorphism are two key features introduced in the ML family of languages, which have already been widely exploited for structuring programs: Haskell and ML programs are often more elegant and more correct by construction. Still, we sometimes need code to be refactored or adapted to be reused in a slightly different context. While the type system is considerably helpful in these situations, by automatically locating type-inconsistent program points or incomplete pattern matchings, this process could be made safer and more automated by further exploiting parametricity. We propose a posteriori program abstraction as a principle for such code transformations. We apply this principle to ornamentation which is a way to describe changes in datatype definitions reorganizing, adding, or dropping some pieces of data so that functions operating on the bare definition can be partially and sometimes totally lifted into functions operating on the ornamented structure. We view ornamentation as an a posteriori abstraction of the bare code, called a generic lifting, which can then be instantiated into a concrete lifting, meta-reduced, and simplified. Both the source and target code live in core ML while the lifted code lives in a meta-language above ML equipped with a limited form of dependent types needed to capture some invariants of the generic lifting so that the concrete lifting can be simplified back into an ML program. Importantly, the lifted code can be closely related to the bare code, using logical relations thanks to the generic lifting detour. Different, typical use cases of ornaments will be shown and the approach will be mainly illustrated on examples.","PeriodicalId":312246,"journal":{"name":"Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell","volume":"407 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2017-09-07","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"2","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the 10th ACM SIGPLAN International Symposium on Haskell","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/3122955.3127333","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 2

Abstract

Inductive datatypes and parametric polymorphism are two key features introduced in the ML family of languages, which have already been widely exploited for structuring programs: Haskell and ML programs are often more elegant and more correct by construction. Still, we sometimes need code to be refactored or adapted to be reused in a slightly different context. While the type system is considerably helpful in these situations, by automatically locating type-inconsistent program points or incomplete pattern matchings, this process could be made safer and more automated by further exploiting parametricity. We propose a posteriori program abstraction as a principle for such code transformations. We apply this principle to ornamentation which is a way to describe changes in datatype definitions reorganizing, adding, or dropping some pieces of data so that functions operating on the bare definition can be partially and sometimes totally lifted into functions operating on the ornamented structure. We view ornamentation as an a posteriori abstraction of the bare code, called a generic lifting, which can then be instantiated into a concrete lifting, meta-reduced, and simplified. Both the source and target code live in core ML while the lifted code lives in a meta-language above ML equipped with a limited form of dependent types needed to capture some invariants of the generic lifting so that the concrete lifting can be simplified back into an ML program. Importantly, the lifted code can be closely related to the bare code, using logical relations thanks to the generic lifting detour. Different, typical use cases of ornaments will be shown and the approach will be mainly illustrated on examples.
装饰:利用参数来实现更安全、更自动化的代码重构和代码重用(特邀演讲)
归纳数据类型和参数多态性是ML语言家族中引入的两个关键特性,它们已经被广泛用于结构化程序:Haskell和ML程序通常在构造上更优雅、更正确。尽管如此,我们有时还是需要对代码进行重构或调整,以便在稍微不同的上下文中重用。虽然类型系统在这些情况下非常有用,但通过自动定位类型不一致的程序点或不完整的模式匹配,可以通过进一步利用参数性使该过程更安全、更自动化。我们提出一个后验程序抽象作为这种代码转换的原则。我们将这一原则应用于修饰,修饰是一种描述数据类型定义变化的方式,重组、添加或删除一些数据块,以便在裸定义上操作的函数可以部分或有时完全提升为在修饰结构上操作的函数。我们将装饰视为裸代码的后验抽象,称为通用提升,然后可以将其实例化为具体的提升,元简化和简化。源代码和目标代码都位于核心ML中,而被提升的代码则位于ML之上的元语言中,该元语言配备了有限形式的依赖类型,这些依赖类型用于捕获泛型提升的一些不变量,以便将具体提升简化回ML程序。重要的是,提升的代码可以通过使用逻辑关系与裸代码紧密相关,这得益于通用提升的迂回。将展示不同的、典型的装饰品用例,并主要通过示例说明该方法。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 求助全文
来源期刊
自引率
0.00%
发文量
0
×
引用
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学术官方微信
小红书