OCaml 中的比较不再是多态的了吗?
Are comparisons in OCaml no longer polymorphic?
我一直在尝试将代码库从 OCaml 4.04 迁移到 OCaml 4.10。我一直 运行 遇到一个反复出现的错误,当我比较非整数的值时,出现类型错误:
if (total < current) then (...)
90 | if (total < current) then (...)
^^^^^
Error: This expression has type float but an expression was expected of type
int
但将其替换为 if Float.(total < current)
可以解决问题。是我做错了什么,还是 OCaml 中的比较不再是多态的?
行为的改变似乎是由于我使用了 Jane Street Core。 OCaml 运算符仍然是多态的,但使用 Core 会强制您使用显式类型比较。
https://discuss.ocaml.org/t/removing-polymorphic-compare-from-core/2994
我一直在尝试将代码库从 OCaml 4.04 迁移到 OCaml 4.10。我一直 运行 遇到一个反复出现的错误,当我比较非整数的值时,出现类型错误:
if (total < current) then (...)
90 | if (total < current) then (...)
^^^^^
Error: This expression has type float but an expression was expected of type
int
但将其替换为 if Float.(total < current)
可以解决问题。是我做错了什么,还是 OCaml 中的比较不再是多态的?
行为的改变似乎是由于我使用了 Jane Street Core。 OCaml 运算符仍然是多态的,但使用 Core 会强制您使用显式类型比较。
https://discuss.ocaml.org/t/removing-polymorphic-compare-from-core/2994