我已经定义了一些类型:功能OCaml中
type box = Box of int
type table = Table of int
type compare_result = Lt | Eq | Gt
看来,OCaml中,我们不能定义2个功能与同名但不同类型的参数:
let compare (a: box) (b: box): compare_result = (...)
let compare (a: table) (b: table): compare_result = (...)
let res_box = compare (Box 1) (Box 2) in (* which is supposed to call the first funciton *)
let res_table = compare (Table 1) (Table 2) in (* which is supposed to call the second function *)
所以任何人都可以告诉我在OCaml中做什么替代方法?我们必须以不同的方式命名这两个功能吗?
请注意,您的第二个'compare'声明将隐藏前一个(在Ocaml中没有函数重载)。 – akoprowski