Choosing is Losing: How to combine the benefits of shallow and deep embeddings through reflection

05/22/2021
by   Artjoms Sinkarovs, et al.
0

Dependently-typed host languages empower users to verify a wide range of properties of embedded languages and programs written in them. Designers of such embedded languages are faced with a difficult choice between using a shallow or a deep embedding. The former is easier to use because the entire infrastructure of the host langauge is immediately available. Meanwhile, the latter gives full access to the structure of embedded programs, but is difficult to use in practice, especially when the embedded language is itself dependently typed. The main insight presented in this paper is that the choice between shallow and deep embedding can be eliminated by working in a host language with reflection capabilities: we start from a shallow embedding that can use all libraries and tools of the host language, and later use reflection to expose the deep structure of the embedded programs. Concretely, we apply this technique to embed three programming languages – Kaleidoscope, SaC, and (a subset of) APL – into the dependently typed theorem prover Agda, using dependent types to statically enforce several properties of interest. We then use Agda's reflection capabilities to extract the embedded programs back into the original language, so that the existing toolchain can be leveraged. In this process, statically verified properties of the host language are mapped onto runtime checks in the target language, allowing extracted programs to interact safely with existing code. Finally, we demonstrate the feasibility of our approach with the implementation and extraction of a convolutional neural network in our embedding of APL.

READ FULL TEXT
research
05/18/2020

Sham: A DSL for Fast DSLs

Domain-specific languages (DSLs) are touted as both easy to embed in pro...
research
08/30/2021

Embedded Pattern Matching

Haskell is a popular choice for hosting deeply embedded languages. A rec...
research
12/20/2021

Image quality enhancement of embedded holograms in holographic information hiding using deep neural networks

Holographic information hiding is a technique for embedding holograms or...
research
02/01/2019

Shallow EDSLs and Object-Oriented Programming: Beyond Simple Compositionality

Context: Embedded Domain-Specific Languages (EDSLs) are a common and wid...
research
07/24/2019

ConCert: A Smart Contract Certification Framework in Coq

We present a new way of embedding functional languages into the Coq proo...
research
11/13/2022

Choice Trees: Representing Nondeterministic, Recursive, and Impure Programs in Coq

This paper introduces Choice Trees (ctrees), a monad for modeling nondet...
research
05/24/2022

A Proof-Generating C Code Generator for ACL2 Based on a Shallow Embedding of C in ACL2

This paper describes a C code generator for ACL2 that recognizes ACL2 re...

Please sign up or login with your details

Forgot password? Click here to reset