一句话:将类型化函数式程序经保持语义的变换编译到不同范畴,以统一实现硬件电路、自动微分、增量计算等解释。
本文基于简单类型 lambda 演算可由任意笛卡尔闭范畴(CCC)建模这一事实,提出为类型化函数式程序赋予多种范畴解释。实现方式是在现有编译器(如 GHC)中加入一组保持语义的变换,将程序编译到目标范畴。每个解释只需在 Haskell 中(编译器之外)定义相应范畴,无需深层嵌入 DSL。作者展示了该方法在硬件电路、自动微分、增量计算和区间分析等场景的应用,并认为这种通用技术是深层嵌入领域特定语言的有力替代方案。
It is well-known that the simply typed lambda-calculus is modeled by any cartesian closed category (CCC). This correspondence suggests giving typed functional programs a variety of interpretations, each corresponding to a different category. A convenient way to realize this idea is as a collection of meaning-preserving transformations added to an existing compiler, such as GHC for Haskell. This paper describes such an implementation and demonstrates its use for a variety of interpretations including hardware circuits, automatic differentiation, incremental computation, and interval analysis. Each such interpretation is a category easily defined in Haskell (outside of the compiler). The general technique appears to provide a compelling alternative to deeply embedded domain-specific languages.