Combining deep and shallow embedding of domain-specific languages

We present a technique to combine deep and shallow embedding in the context of compiling embedded languages in order to provide the benefits of both techniques. When compiling embedded languages it is natural to use an abstract syntax tree to represent programs. This is known as a deep embedding and it is a rather cumbersome technique compared to other forms of embedding, typically leading to more code and being harder to extend. In shallow embeddings, language constructs are mapped directly to their semantics which yields more flexible and succinct implementations. But shallow embeddings are not well-suited for compiling embedded languages. Our technique uses a combination of deep and shallow embedding, which helps keeping the deep embedding small and makes extending the embedded language much easier. The technique also has some unexpected but welcome secondary effects. It provides fusion of functions to remove intermediate results for free without any additional effort. It also helps us to give the embedded language a more natural programming interface.

[1]  Simon L. Peyton Jones,et al.  Lazy functional state threads , 1994, PLDI '94.

[2]  Martin Odersky,et al.  Higher-order and Symbolic Computation Manuscript No. Scala-virtualized: Linguistic Reuse for Deep Embeddings , 2022 .

[3]  Oege de Moor,et al.  Compiling embedded languages , 2003, J. Funct. Program..

[4]  Koen Claessen,et al.  Observable Sharing for Functional Circuit Description , 1999, ASIAN.

[5]  Emil Axelsson,et al.  Generic Monadic Constructs for Embedded Languages , 2011, IFL.

[6]  Simon L. Peyton Jones,et al.  A short cut to deforestation , 1993, FPCA '93.

[7]  Paul Hudak,et al.  Keynote Address - The Promise of Domain-Specific Languages , 1997, DSL.

[8]  Apostolos Syropoulos,et al.  Steps in Scala: The expression problem , 2010 .

[9]  Bo Joel Svensson,et al.  Expressive array constructs in an embedded GPU kernel programming language , 2012, DAMP '12.

[10]  Oleg Kiselyov Implementing Explicit and Finding Implicit Sharing in Embedded DSLs , 2011, DSL.

[11]  Andy Gill,et al.  Type-safe observable sharing in Haskell , 2009, Haskell.

[12]  Mary Sheeran,et al.  Lava: hardware design in Haskell , 1998, ICFP '98.

[13]  Koen Claessen,et al.  Using circular programs for higher-order syntax: functional pearl , 2013, ICFP.

[14]  Frank Pfenning,et al.  Higher-order abstract syntax , 1988, PLDI '88.

[15]  Bo Joel Svensson,et al.  Simple and compositional reification of monadic embedded languages , 2013, ICFP.

[16]  Andy Gill,et al.  Sunroof: A Monadic DSL for Generating JavaScript , 2014, PADL.

[17]  Adam Chlipala Parametric higher-order abstract syntax for mechanized semantics , 2008, ICFP 2008.

[18]  OderskyMartin,et al.  Lightweight modular staging , 2010 .

[19]  Zoltán Horváth,et al.  Feldspar: A domain specific language for digital signal processing algorithms , 2010, Eighth ACM/IEEE International Conference on Formal Methods and Models for Codesign (MEMOCODE 2010).

[20]  Martin Odersky,et al.  Yin-yang: concealing the deep embedding of DSLs , 2014, GPCE 2014.

[21]  Trevor L. McDonell Optimising purely functional GPU programs , 2013, ICFP.

[22]  Simon L. Peyton Jones,et al.  Regular, shape-polymorphic, parallel arrays in Haskell , 2010, ICFP '10.

[23]  Zoltán Horváth,et al.  Efficient Code Generation from the High-level Domain-specific Language Feldspar for DSPs , 2010, CGO 2010.

[24]  Peyton Jones,et al.  Haskell 98 language and libraries : the revised report , 2003 .

[25]  Graham Hutton,et al.  Compilation à la Carte , 2013, IFL '13.

[26]  Josef Svenningsson,et al.  An EDSL approach to high performance Haskell programming , 2013, Haskell '13.

[27]  Tim Sheard,et al.  Revisiting catamorphisms over datatypes with embedded functions (or, programs from outer space) , 1996, POPL '96.

[28]  Emil Axelsson,et al.  Combining Deep and Shallow Embedding for EDSL , 2012, Trends in Functional Programming.

[29]  Jacques Carette,et al.  Finally Tagless, Partially Evaluated , 2007, APLAS.

[30]  Bo Joel Svensson,et al.  Obsidian: A Domain Specific Embedded Language for Parallel Programming of Graphics Processors , 2008, IFL.

[31]  Martin Odersky,et al.  Lightweight modular staging: a pragmatic approach to runtime code generation and compiled DSLs , 2010, GPCE '10.

[32]  Garrin Kimmell,et al.  What's the Matter with Kansas Lava? , 2010, Trends in Functional Programming.

[33]  Gordon J. Pace,et al.  An embedded language framework for hardware compilation , 2002 .

[34]  Janis Voigtländer,et al.  Asymptotic Improvement of Computations over Free Monads , 2008, MPC.

[35]  Nicolas Wu,et al.  Folding domain-specific languages , 2014, ICFP.

[36]  Mary Sheeran,et al.  The Design and Implementation of Feldspar - An Embedded Language for Digital Signal Processing , 2010, IFL.

[37]  Henrik Nilsson,et al.  Mixed-Level Embedding and JIT Compilation for an Iteratively Staged DSL , 2010, WFLP.

[38]  Andy Gill,et al.  The constrained-monad problem , 2013, ICFP.

[39]  Shigeru Chiba,et al.  Implicit Staging of EDSL Expressions: A Bridge between Shallow and Deep Embedding , 2014, ECOOP.

[40]  Tristan Bull,et al.  Types and Type Families for Hardware Simulation and Synthesis - The Internals and Externals of Kansas Lava , 2010, Trends in Functional Programming.

[41]  Jacques Carette,et al.  Finally tagless, partially evaluated: Tagless staged interpreters for simpler typed languages , 2007, Journal of Functional Programming.

[42]  Pieter Koopman,et al.  IFL'13: Proceedings of the 25th Symposium on Implementation and Application of Functional Languages, Nijmegen, Netherlands — August 28 - 30, 2013 , 2014 .

[43]  Wouter Swierstra,et al.  Data types à la carte , 2008, Journal of Functional Programming.

[44]  Martin Odersky,et al.  Scala-virtualized , 2012, PEPM '12.

[45]  Martin Fowler,et al.  Domain-Specific Languages , 2010, The Addison-Wesley signature series.