在OCaml中取消相互递归类型定义的装箱
Unboxing Mutually Recursive Type Definitions in OCaml
摘要:
在现代OCaml中,单参数数据类型声明(具有单个构造函数的变量,具有单个字段的记录)有时可以“取消装箱”。这意味着它们的内存表示与它们的单个参数相同(省略了变量或记录构造函数和间接),从而实现了更好的时间和内存效率。然而,在广义/保护代数数据库(GADT)的情况下,由于对OCaml值的运行时表示的微妙假设,拆箱并不总是可能的。目前的正确性检查是不完整的,拒绝了许多有效的定义,特别是那些涉及相互递归的数据类型声明。在本文中,我们解释了分离性的概念作为一个语义的拆箱标准,并提出了一套推理规则来检查分离性。从这些推理规则中,我们得到了一个新的实现的拆箱检查,正确地支持相互递归的定义。
英文摘要:
In modern OCaml, single-argument datatype declarations (variants with a single constructor, records with a single field) can sometimes be `unboxed'. This means that their memory representation is the same as their single argument (omitting the variant or record constructor and an indirection), thus achieving better time and memory efficiency. However, in the case of generalized/guarded algebraic datatypes (GADTs), unboxing is not always possible due to a subtle assumption about the runtime representation of OCaml values. The current correctness check is incomplete, rejecting many valid definitions, in particular those involving mutually-recursive datatype declarations. In this paper, we explain the notion of separability as a semantic for the unboxing criterion, and propose a set of inference rules to check separability. From these inference rules, we derive a new implementation of the unboxing check that properly supports mutually-recursive definitions.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。