Squid: type-safe, hygienic, and reusable quasiquotes

L. Parreaux, A. Shaikhha, Christoph E. Koch
{"title":"Squid: type-safe, hygienic, and reusable quasiquotes","authors":"L. Parreaux, A. Shaikhha, Christoph E. Koch","doi":"10.1145/3136000.3136005","DOIUrl":null,"url":null,"abstract":"Quasiquotes have been shown to greatly simplify the task of metaprogramming. This is in part because they hide the data structures of the intermediate representation (IR), instead allowing metaprogrammers to use the concrete syntax of the language they manipulate. Scala has had \"syntactic\" quasiquotes for a long time, but still misses a statically-typed version like in MetaOCaml, Haskell and F#. This safer flavor of quasiquotes has been particularly useful for staging and domain-specific languages. In this paper we present Squid, a metaprogramming system for Scala that fills this gap. Squid quasiquotes are novel in three ways: they are the first statically-typed quasiquotes we know that allow code inspection (via pattern matching); they are implemented purely as a macro library, without modifications to the compiler; and they are reusable in the sense that they can manipulate different IRs. Adapting (or binding) a new IR to Squid is done simply by implementing a well-defined interface in the style of object algebras (i.e., tagless-final). We detail how Squid is implemented, leveraging the metaprogramming tools already offered by Scala, and show three application examples: the definition of a binding for a DSL in the style of LMS; a safe ANF conversion; and the introduction of type-safe, hygienic macros as an alternative to the current macro system.","PeriodicalId":158126,"journal":{"name":"Proceedings of the 8th ACM SIGPLAN International Symposium on Scala","volume":"62 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2017-10-22","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"10","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the 8th ACM SIGPLAN International Symposium on Scala","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/3136000.3136005","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 10

Abstract

Quasiquotes have been shown to greatly simplify the task of metaprogramming. This is in part because they hide the data structures of the intermediate representation (IR), instead allowing metaprogrammers to use the concrete syntax of the language they manipulate. Scala has had "syntactic" quasiquotes for a long time, but still misses a statically-typed version like in MetaOCaml, Haskell and F#. This safer flavor of quasiquotes has been particularly useful for staging and domain-specific languages. In this paper we present Squid, a metaprogramming system for Scala that fills this gap. Squid quasiquotes are novel in three ways: they are the first statically-typed quasiquotes we know that allow code inspection (via pattern matching); they are implemented purely as a macro library, without modifications to the compiler; and they are reusable in the sense that they can manipulate different IRs. Adapting (or binding) a new IR to Squid is done simply by implementing a well-defined interface in the style of object algebras (i.e., tagless-final). We detail how Squid is implemented, leveraging the metaprogramming tools already offered by Scala, and show three application examples: the definition of a binding for a DSL in the style of LMS; a safe ANF conversion; and the introduction of type-safe, hygienic macros as an alternative to the current macro system.
查看原文
分享 分享
微信好友 朋友圈 QQ好友 复制链接
本刊更多论文
Squid:类型安全、卫生和可重用的准引用
准引号已经被证明可以极大地简化元编程的任务。这在一定程度上是因为它们隐藏了中间表示(IR)的数据结构,而不是允许元程序员使用他们操作的语言的具体语法。Scala已经有“语法”准引号很长时间了,但是仍然缺少静态类型的版本,比如MetaOCaml、Haskell和f#。这种更安全的准引号风格对于阶段语言和特定于领域的语言特别有用。在本文中,我们介绍了Squid,一个用于Scala的元编程系统,它填补了这一空白。Squid准引号在三个方面是新颖的:它们是我们所知道的第一个允许代码检查(通过模式匹配)的静态类型准引号;它们完全作为宏库实现,不需要修改编译器;它们是可重复使用的,因为它们可以操纵不同的ir。将一个新的IR适配(或绑定)到Squid,只需以对象代数(即tagless-final)的风格实现一个定义良好的接口即可完成。我们详细介绍了Squid是如何实现的,利用Scala已经提供的元编程工具,并展示了三个应用示例:以LMS风格为DSL定义绑定;安全的ANF转换;以及引入类型安全、卫生的宏作为当前宏系统的替代方案。
本文章由计算机程序翻译,如有差异,请以英文原文为准。
求助全文
约1分钟内获得全文 去求助
来源期刊
自引率
0.00%
发文量
0
期刊最新文献
Interactive development using the Dotty compiler (tool paper) Effekt: extensible algebraic effects in Scala (short paper) Spark and Scala (keynote) Squid: type-safe, hygienic, and reusable quasiquotes Kompics Scala: narrowing the gap between algorithmic specification and executable code (short paper)
×
引用
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