属性语法是一流的:如何在Haskell中进行面向方面的编程

Marcos Viera, S. Swierstra, Wouter Swierstra
{"title":"属性语法是一流的:如何在Haskell中进行面向方面的编程","authors":"Marcos Viera, S. Swierstra, Wouter Swierstra","doi":"10.1145/1596550.1596586","DOIUrl":null,"url":null,"abstract":"Attribute Grammars (AGs), a general-purpose formalism for describing recursive computations over data types, avoid the trade-off which arises when building software incrementally: should it be easy to add new data types and data type alternatives or to add new operations on existing data types? However, AGs are usually implemented as a pre-processor, leaving e.g. type checking to later processing phases and making interactive development, proper error reporting and debugging difficult. Embedding AG into Haskell as a combinator library solves these problems.\n Previous attempts at embedding AGs as a domain-specific language were based on extensible records and thus exploiting Haskell's type system to check the well formedness of the AG, but fell short in compactness and the possibility to abstract over oft occurring AG patterns. Other attempts used a very generic mapping for which the AG well-formedness could not be statically checked.\n We present a typed embedding of AG in Haskell satisfying all these requirements. The key lies in using HList-like typed heterogeneous collections (extensible polymorphic records) and expressing AG well-formedness conditions as type-level predicates (i.e., type-class constraints). By further type-level programming we can also express common programming patterns, corresponding to the typical use cases of monads such as Reader, Writer and State. The paper presents a realistic example of type-class-based type-level programming in Haskell.","PeriodicalId":20504,"journal":{"name":"Proceedings of the 18th ACM SIGPLAN international conference on Functional programming","volume":"21 1","pages":"245-256"},"PeriodicalIF":0.0000,"publicationDate":"2009-08-31","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"47","resultStr":"{\"title\":\"Attribute grammars fly first-class: how to do aspect oriented programming in Haskell\",\"authors\":\"Marcos Viera, S. Swierstra, Wouter Swierstra\",\"doi\":\"10.1145/1596550.1596586\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"Attribute Grammars (AGs), a general-purpose formalism for describing recursive computations over data types, avoid the trade-off which arises when building software incrementally: should it be easy to add new data types and data type alternatives or to add new operations on existing data types? However, AGs are usually implemented as a pre-processor, leaving e.g. type checking to later processing phases and making interactive development, proper error reporting and debugging difficult. Embedding AG into Haskell as a combinator library solves these problems.\\n Previous attempts at embedding AGs as a domain-specific language were based on extensible records and thus exploiting Haskell's type system to check the well formedness of the AG, but fell short in compactness and the possibility to abstract over oft occurring AG patterns. Other attempts used a very generic mapping for which the AG well-formedness could not be statically checked.\\n We present a typed embedding of AG in Haskell satisfying all these requirements. The key lies in using HList-like typed heterogeneous collections (extensible polymorphic records) and expressing AG well-formedness conditions as type-level predicates (i.e., type-class constraints). By further type-level programming we can also express common programming patterns, corresponding to the typical use cases of monads such as Reader, Writer and State. The paper presents a realistic example of type-class-based type-level programming in Haskell.\",\"PeriodicalId\":20504,\"journal\":{\"name\":\"Proceedings of the 18th ACM SIGPLAN international conference on Functional programming\",\"volume\":\"21 1\",\"pages\":\"245-256\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"2009-08-31\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"47\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"Proceedings of the 18th ACM SIGPLAN international conference on Functional programming\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.1145/1596550.1596586\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the 18th ACM SIGPLAN international conference on Functional programming","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/1596550.1596586","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 47

摘要

属性语法(Attribute Grammars, AGs)是一种用于描述数据类型递归计算的通用形式,它避免了增量构建软件时出现的权衡:添加新数据类型和数据类型替代方案是否容易,或者在现有数据类型上添加新操作是否容易?然而,AGs通常是作为预处理器来实现的,将类型检查等问题留到后面的处理阶段,使交互式开发、适当的错误报告和调试变得困难。将AG作为组合子库嵌入Haskell解决了这些问题。之前将AGs作为特定于领域的语言嵌入的尝试是基于可扩展的记录,从而利用Haskell的类型系统来检查AG的良好格式,但在紧凑性和抽象经常出现的AG模式的可能性方面存在不足。其他尝试使用了非常通用的映射,无法静态检查AG的格式良好性。我们在Haskell中给出了一种满足所有这些要求的AG类型嵌入。关键在于使用类hlist类型异构集合(可扩展多态记录),并将AG格式良好的条件表示为类型级谓词(即类型-类约束)。通过进一步的类型级编程,我们还可以表达常见的编程模式,对应于单子(如Reader、Writer和State)的典型用例。本文给出了一个在Haskell中基于类型-类的类型级编程的实例。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
Attribute grammars fly first-class: how to do aspect oriented programming in Haskell
Attribute Grammars (AGs), a general-purpose formalism for describing recursive computations over data types, avoid the trade-off which arises when building software incrementally: should it be easy to add new data types and data type alternatives or to add new operations on existing data types? However, AGs are usually implemented as a pre-processor, leaving e.g. type checking to later processing phases and making interactive development, proper error reporting and debugging difficult. Embedding AG into Haskell as a combinator library solves these problems. Previous attempts at embedding AGs as a domain-specific language were based on extensible records and thus exploiting Haskell's type system to check the well formedness of the AG, but fell short in compactness and the possibility to abstract over oft occurring AG patterns. Other attempts used a very generic mapping for which the AG well-formedness could not be statically checked. We present a typed embedding of AG in Haskell satisfying all these requirements. The key lies in using HList-like typed heterogeneous collections (extensible polymorphic records) and expressing AG well-formedness conditions as type-level predicates (i.e., type-class constraints). By further type-level programming we can also express common programming patterns, corresponding to the typical use cases of monads such as Reader, Writer and State. The paper presents a realistic example of type-class-based type-level programming in Haskell.
求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
1ML - core and modules united (F-ing first-class modules) Functional programming for dynamic and large data with self-adjusting computation A theory of gradual effect systems Building embedded systems with embedded DSLs Homotopical patch theory
×
引用
GB/T 7714-2015
复制
MLA
复制
APA
复制
导出至
BibTeX EndNote RefMan NoteFirst NoteExpress
×
×
提示
您的信息不完整,为了账户安全,请先补充。
现在去补充
×
提示
您因"违规操作"
具体请查看互助需知
我知道了
×
提示
现在去查看 取消
×
提示
确定
0
微信
客服QQ
Book学术公众号 扫码关注我们
反馈
×
意见反馈
请填写您的意见或建议
请填写您的手机或邮箱
已复制链接
已复制链接
快去分享给好友吧!
我知道了
×
扫码分享
扫码分享
Book学术官方微信
Book学术文献互助
Book学术文献互助群
群 号:481959085
Book学术
文献互助 智能选刊 最新文献 互助须知 联系我们:info@booksci.cn
Book学术提供免费学术资源搜索服务,方便国内外学者检索中英文文献。致力于提供最便捷和优质的服务体验。
Copyright © 2023 Book学术 All rights reserved.
ghs 京公网安备 11010802042870号 京ICP备2023020795号-1