一句话:提出 StrictCheck,用基于属性的随机测试规定并检验 Haskell 函数的严格性。
严格性通常被视为非函数式属性,难以直接规定与测试。本文提出 StrictCheck:一个基于属性的随机测试框架,用于观察、规定和测试 Haskell 函数的严格性。它通过具体化(reify)对数据结构的求值需求,使其能在 Haskell 内被操纵与检查。为此需解决三点:精确规定函数严格性、高效观察数据结构求值、正确生成具有随机严格性的函数。StrictCheck 能以常数因子开销测试任意 Haskell 函数(含高阶函数),且对 Haskell 标准代数数据类型无需模板代码;其低层但表达力强的规约语言可作为未来高层抽象的基础。作者还用它为 Okasaki 常数时间纯函数队列建立了正确规约,该结构性质本质上依赖微妙的惰性使用。
We introduce StrictCheck: a property-based random testing framework for observing, specifying, and testing the strictness of Haskell functions. Strictness is traditionally considered a non-functional property; StrictCheck allows it to be tested as if it were one, by reifying demands on data structures so they can be manipulated and examined within Haskell. Testing strictness requires us to 1) precisely specify the strictness of functions, 2) efficiently observe the evaluation of data structures, and 3) correctly generate functions with random strictness. We tackle all three of these challenges, designing an efficient generic framework for precise dynamic strictness testing. StrictCheck can specify and test the strictness of any Haskell function---including higher-order ones---with only a constant factor of overhead, and requires no boilerplate for testing functions on Haskell-standard algebraic data types. We provide an expressive but low-level specification language as a foundation upon which to build future higher-level abstractions. We demonstrate a non-trivial application of our library, developing a correct specification of a data structure whose properties intrinsically rely on subtle use of laziness: Okasaki's constant-time purely functional queue.