OCaml - Base 导致元组解构问题

OCaml - Base causes issue with tuple destructuring

Base添加到以下代码时,为什么OCaml编译器期望hwinttup 应该是一个元组 - 是否存在句法问题?导致此错误的 Base 是什么?

open Base

let () =
  let tup = ("hello", "world") in
  let h, w = tup in
  if h = w then print_endline "equal" else print_endline "not equal"

错误:

91 |   if h = w then print_endline "equal" else print_endline "not equal"
          ^
Error: This expression has type string but an expression was expected of type
         int

Base 库删除了多态比较。您可以这样使用运算符:

open Base

let () =
  let tup = ("hello", "world") in
  let h, w = tup in
  if String.(h = w) then print_endline "equal" 
  else print_endline "not equal"

编辑:如果解释没有说清楚,Base 库不会影响 OCaml 如何处理元组。

Base 与其他 Janestreet 库一起,不鼓励多态比较函数,并隐藏 compare(=) 和其他运算符及其单态等价物。他们或多或少地选择了比较整数的函数(遵循 SML 传统)。

您仍然可以获得多态比较函数,使用

open Poly

或者,在本地,

let true = Poly.((1,2) = (1,2))