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.\@
翻译:独立型主机语言使用户能够核实嵌入语言及其中写成的程式的广泛特性。 这些嵌入语言的设计者在使用浅层或深层嵌入器之间面临着艰难的选择。 前者更容易使用, 因为主机 Langaugue 的整个基础设施立即可用。 同时, 后者允许完全使用嵌入程序的结构, 但在实践中很难使用, 特别是当嵌入语言本身是依附打字型的, 特别是当嵌入语言本身被打字时。 本文的主要见解是, 浅层和深层嵌入器之间的选择可以通过具有反射能力的主机语言来消除: 我们从一个浅层嵌入器开始, 可以使用主机语言的所有图书馆和工具, 然后再使用反射器来暴露嵌入程序。 具体地说, 我们应用这一技术将三种程序嵌入嵌入嵌入嵌入程序, Kaleidooproc, SaC, 和 (一个子组) APL - 嵌入依附型型的Oraloral 证明 阿格达,, 使用依附型型型类型, 静态执行若干种感兴趣的特性。 我们然后使用 Agda 的反演算能力将内嵌内内嵌入程序带的内置的内嵌入式程序,, 将Sliversalevolevoleval 将现有工具程序升级到原始版本进行升级到最后版本的版本的版本的版本的版本的版本, 。