请考虑以下代码:
module A =
struct
type r = { i : int; s: string }
end
module B =
struct
type r = { i : int; s : string }
end
let f (x : A.r) : B.r = match x with
{ i; s } -> { i = 2*i; s = "" }
Run Code Online (Sandbox Code Playgroud)
两个模块定义完全相同的记录.函数f将A记录转换为B记录.警告已在编译期间发出,但也可以交互显示.在ocaml cli上,似乎对f的调用完成了预期的事情:
# let x = f { i = 5; s = "ab" };;
Characters 10-29:
let x = f { i = …
Run Code Online (Sandbox Code Playgroud) ocaml ×1