执行类型推断的代码
我正在研究一种具有全局多态类型推断的实验性编程语言。
我最近让该算法运行得足够好,可以正确输入我扔给它的示例代码。我现在正在寻找更复杂的东西来练习边缘情况。
谁能指出我可以用于此目的的非常粗糙和可怕的代码片段的来源?我确信函数式编程世界里有很多这样的东西。我特别寻找用函数递归做坏事的例子,因为我需要检查以确保函数扩展正确终止,但一切都很好——我需要构建一个测试套件。有什么建议吗?
我的语言很大程度上是命令式的,但任何 ML 风格的代码都应该很容易转换。
I'm working on an experimental programming language that has global polymorphic type inference.
I recently got the algorithm working sufficiently well to correctly type the bits of sample code I'm throwing at it. I'm now looking for something more complex that will exercise the edge cases.
Can anyone point me at a source of really gnarly and horrible code fragments that I can use for this? I'm sure the functional programming world has plenty. I'm particularly looking for examples that do evil things with function recursion, as I need to check to make sure that function expansion terminates correctly, but anything's good --- I need to build a test suite. Any suggestions?
My language is largely imperative, but any ML-style code ought to be easy to convert.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我的总体策略实际上是从相反的方向接近它——确保它拒绝不正确的东西!
也就是说,这里是我通常使用的一些标准“确认”测试:
急切的固定点组合器(无耻地从 此处):
明显的相互递归:
也请检查那些深度嵌套的 let 表达式:
深度嵌套的高阶函数!
我不知道是否必须有值限制才能合并可变引用。如果是这样,看看会发生什么:
您可能需要以标准方式实现
map
和rev
:)然后使用实际引用(从 此处):
希望这些能在某种程度上有所帮助。确保尝试构建一组可以以某种自动方式重新运行的回归测试,以确保所有类型推断在您所做的所有更改中都能正确运行:)
My general strategy is actually to approach it from the opposite direction -- ensure that it rejects incorrect things!
That said, here are some standard "confirmation" tests I usually use:
The eager fix point combinator (unashamedly stolen from here):
Obvious mutual recursion:
Check out those deeply nested let expressions too:
Deeply nested higher order functions!
I don't know if you have to have the value restriction in order to incorporate mutable references. If so, see what happens:
You might need to implement
map
andrev
in the standard way :)Then with actual references lying around (stolen from here):
Hope these help in some way. Make sure to try to build a set of regression tests you can re-run in some automatic fashion to ensure that all of your type inference behaves correctly through all changes you make :)