{"title":"使用元编程的浅层嵌入式领域特定语言中的一等数据类型","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":"{\"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}","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}
First-Class Data Types in Shallow Embedded Domain-Specific Languages using Metaprogramming
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.