{"title":"First-Class Data Types in Shallow Embedded Domain-Specific Languages using Metaprogramming","authors":"Mart Lubbers, P. Koopman, R. Plasmeijer","doi":"10.1145/3587216.3587219","DOIUrl":null,"url":null,"abstract":"Functional programming languages are excellent for hosting embedded domain specific languages (eDSLs) because of their rich type systems, minimal syntax, and referential transparency. However, data types defined in the host language are not automatically available in the embedded language. To do so, all the operations on the data type must be ported to the eDSL resulting in a lot of boilerplate. This paper shows that by using metaprogramming, all first-order user-defined data types can be automatically made first class in shallow embedded DSLs. We show this by providing an implementation in Template Haskell for a typical DSL with two different semantics. Furthermore, we show that by utilising quasiquotation, there is hardly any burden on the syntax. Finally, the paper also serves as a gentle introduction to Template Haskell.","PeriodicalId":318613,"journal":{"name":"Proceedings of the 34th Symposium on Implementation and Application of Functional Languages","volume":"23 1","pages":"0"},"PeriodicalIF":0.0000,"publicationDate":"2022-08-31","publicationTypes":"Journal Article","fieldsOfStudy":null,"isOpenAccess":false,"openAccessPdf":"","citationCount":"0","resultStr":null,"platform":"Semanticscholar","paperid":null,"PeriodicalName":"Proceedings of the 34th Symposium on Implementation and Application of Functional Languages","FirstCategoryId":"1085","ListUrlMain":"https://doi.org/10.1145/3587216.3587219","RegionNum":0,"RegionCategory":null,"ArticlePicture":[],"TitleCN":null,"AbstractTextCN":null,"PMCID":null,"EPubDate":"","PubModel":"","JCR":"","JCRName":"","Score":null,"Total":0}
引用次数: 0
Abstract
Functional programming languages are excellent for hosting embedded domain specific languages (eDSLs) because of their rich type systems, minimal syntax, and referential transparency. However, data types defined in the host language are not automatically available in the embedded language. To do so, all the operations on the data type must be ported to the eDSL resulting in a lot of boilerplate. This paper shows that by using metaprogramming, all first-order user-defined data types can be automatically made first class in shallow embedded DSLs. We show this by providing an implementation in Template Haskell for a typical DSL with two different semantics. Furthermore, we show that by utilising quasiquotation, there is hardly any burden on the syntax. Finally, the paper also serves as a gentle introduction to Template Haskell.