用于Haskell的通用递归工具箱:系统地废弃您的样板文件

Deling Ren, Martin Erwig
{"title":"用于Haskell的通用递归工具箱:系统地废弃您的样板文件","authors":"Deling Ren, Martin Erwig","doi":"10.1145/1159842.1159845","DOIUrl":null,"url":null,"abstract":"Haskell programmers who deal with complex data types often need to apply functions to specific nodes deeply nested inside of terms. Typically, implementations for those applications require so-called boilerplate code, which recursively visits the nodes and carries the functions to the places where they need to be applied. The scrap-your-boilerplate approach proposed by Lämmel and Peyton Jones tries to solve this problem by defining a general traversal design pattern that performs the traversal automatically so that the programmers can focus on the code that performs the actual transformation.In practice we often encounter applications that require variations of the recursion schema and call for more sophisticated generic traversals. Defining such traversals from scratch requires a profound understanding of the underlying mechanism and is everything but trivial.In this paper we analyze the problem domain of recursive traversal strategies, by integrating and extending previous approaches. We then extend the scrap-your-boilerplate approach by rich traversal strategies and by a combination of transformations and accumulations, which leads to a comprehensive recursive traversal library Reclib in a statically typed framework.We define a two-layer library targeted at general programmers and programmers with knowledge in traversal strategies. The highlevel interface defines a universal combinator that can be customized to different one-pass traversal strategies with different coverage and different traversal order. The lower-layer interface provides a set of primitives that can be used for defining more sophisticated traversal strategies such as fixpoint traversals. The interfaceis simple and succinct. Like the original scrap-your-boilerplate approach, it makes use of rank-2 polymorphism and functional dependencies, implemented in GHC.","PeriodicalId":188691,"journal":{"name":"ACM SIGPLAN Symposium/Workshop on Haskell","volume":"556 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2006-09-17","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"12","resultStr":"{\"title\":\"A generic recursion toolbox for Haskell or: scrap your boilerplate systematically\",\"authors\":\"Deling Ren, Martin Erwig\",\"doi\":\"10.1145/1159842.1159845\",\"DOIUrl\":null,\"url\":null,\"abstract\":\"Haskell programmers who deal with complex data types often need to apply functions to specific nodes deeply nested inside of terms. Typically, implementations for those applications require so-called boilerplate code, which recursively visits the nodes and carries the functions to the places where they need to be applied. The scrap-your-boilerplate approach proposed by Lämmel and Peyton Jones tries to solve this problem by defining a general traversal design pattern that performs the traversal automatically so that the programmers can focus on the code that performs the actual transformation.In practice we often encounter applications that require variations of the recursion schema and call for more sophisticated generic traversals. Defining such traversals from scratch requires a profound understanding of the underlying mechanism and is everything but trivial.In this paper we analyze the problem domain of recursive traversal strategies, by integrating and extending previous approaches. We then extend the scrap-your-boilerplate approach by rich traversal strategies and by a combination of transformations and accumulations, which leads to a comprehensive recursive traversal library Reclib in a statically typed framework.We define a two-layer library targeted at general programmers and programmers with knowledge in traversal strategies. The highlevel interface defines a universal combinator that can be customized to different one-pass traversal strategies with different coverage and different traversal order. The lower-layer interface provides a set of primitives that can be used for defining more sophisticated traversal strategies such as fixpoint traversals. The interfaceis simple and succinct. Like the original scrap-your-boilerplate approach, it makes use of rank-2 polymorphism and functional dependencies, implemented in GHC.\",\"PeriodicalId\":188691,\"journal\":{\"name\":\"ACM SIGPLAN Symposium/Workshop on Haskell\",\"volume\":\"556 1\",\"pages\":\"0\"},\"PeriodicalIF\":0.0000,\"publicationDate\":\"2006-09-17\",\"publicationTypes\":\"Journal Article\",\"fieldsOfStudy\":null,\"isOpenAccess\":false,\"openAccessPdf\":\"\",\"citationCount\":\"12\",\"resultStr\":null,\"platform\":\"Semanticscholar\",\"paperid\":null,\"PeriodicalName\":\"ACM SIGPLAN Symposium/Workshop on Haskell\",\"FirstCategoryId\":\"1085\",\"ListUrlMain\":\"https://doi.org/10.1145/1159842.1159845\",\"RegionNum\":0,\"RegionCategory\":null,\"ArticlePicture\":[],\"TitleCN\":null,\"AbstractTextCN\":null,\"PMCID\":null,\"EPubDate\":\"\",\"PubModel\":\"\",\"JCR\":\"\",\"JCRName\":\"\",\"Score\":null,\"Total\":0}","platform":"Semanticscholar","paperid":null,"PeriodicalName":"ACM SIGPLAN Symposium/Workshop on Haskell","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/1159842.1159845","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 12

摘要

处理复杂数据类型的Haskell程序员通常需要将函数应用于深嵌套在术语中的特定节点。通常,这些应用程序的实现需要所谓的样板代码,这些代码递归地访问节点并将函数带到需要应用它们的地方。Lämmel和Peyton Jones提出的“废弃样板”方法试图通过定义一个自动执行遍历的通用遍历设计模式来解决这个问题,这样程序员就可以专注于执行实际转换的代码。在实践中,我们经常遇到需要各种递归模式并需要更复杂的泛型遍历的应用程序。从头定义这样的遍历需要对底层机制有深刻的理解,而且非常简单。本文对递归遍历策略的问题域进行了综合和扩展。然后,我们通过丰富的遍历策略以及转换和积累的组合来扩展“废弃样板”方法,从而在静态类型框架中生成全面的递归遍历库Reclib。我们定义了一个针对普通程序员和具有遍历策略知识的程序员的两层库。高级接口定义了一个通用组合子,该组合子可以定制为具有不同覆盖范围和不同遍历顺序的不同单遍遍历策略。底层接口提供了一组原语,可用于定义更复杂的遍历策略,如定点遍历。界面简洁明了。与最初的“废弃样板”方法一样,它利用了GHC中实现的rank-2多态性和功能依赖。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
A generic recursion toolbox for Haskell or: scrap your boilerplate systematically
Haskell programmers who deal with complex data types often need to apply functions to specific nodes deeply nested inside of terms. Typically, implementations for those applications require so-called boilerplate code, which recursively visits the nodes and carries the functions to the places where they need to be applied. The scrap-your-boilerplate approach proposed by Lämmel and Peyton Jones tries to solve this problem by defining a general traversal design pattern that performs the traversal automatically so that the programmers can focus on the code that performs the actual transformation.In practice we often encounter applications that require variations of the recursion schema and call for more sophisticated generic traversals. Defining such traversals from scratch requires a profound understanding of the underlying mechanism and is everything but trivial.In this paper we analyze the problem domain of recursive traversal strategies, by integrating and extending previous approaches. We then extend the scrap-your-boilerplate approach by rich traversal strategies and by a combination of transformations and accumulations, which leads to a comprehensive recursive traversal library Reclib in a statically typed framework.We define a two-layer library targeted at general programmers and programmers with knowledge in traversal strategies. The highlevel interface defines a universal combinator that can be customized to different one-pass traversal strategies with different coverage and different traversal order. The lower-layer interface provides a set of primitives that can be used for defining more sophisticated traversal strategies such as fixpoint traversals. The interfaceis simple and succinct. Like the original scrap-your-boilerplate approach, it makes use of rank-2 polymorphism and functional dependencies, implemented in GHC.
求助全文
通过发布文献求助,成功后即可免费获取论文全文。 去求助
来源期刊
自引率
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学术文献互助群
群 号:481959085
Book学术官方微信