Combining Deep and Shallow Embedding for EDSL

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. 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. In particular it helps keeping the deep embedding small and it makes extending the embedded language much easier. Our technique also has some unexpected but welcome knock-on effects. It provides fusion of functions to remove intermediate results for free without any additional effort. It also helps to give the embedded language a more natural programming interface.

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

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

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

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

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

[6]  P. S. Thiagarajan,et al.  Advances in Computing Science — ASIAN’99 , 1999, Lecture Notes in Computer Science.

[7]  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.

[8]  Koen Claessen,et al.  An embedded language approach to teaching hardware compilation , 2002, SIGP.

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

[10]  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).

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

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

[13]  Mario Rodríguez-Artalejo,et al.  Functional and Constraint Logic Programming , 2001, CCL.

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

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

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

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

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

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

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