short-cutting equality checking in F#?

家住魔仙堡 提交于 2019-12-05 12:47:35

There are two options that I'm aware of. The standard .NET approach would be to use System.Object.ReferenceEquals. A slightly better approach in F# might be to use LanguagePrimitives.PhysicalEquality which is basically identical, but only works on reference types (which is probably correct for your purposes) and requires both arguments to have the same static type. You can also define a custom operator of your choice in terms of either of these functions if you'd like nicer syntax.

As an aside, on .NET I get an infinite loop but not a stack overflow when I run your code, presumably due to tail call optimization.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!