Ocaml 中的输入和“nonrec”

nic*_*las 0 ocaml

我有一个令人费解的例子,下面的“ok”,我完全不明白。

module File1_intf = struct
  type type1 = { nat : int }

  module type Intf = sig
    type nonrec type1 = type1
  end
end

module File1 : File1_intf.Intf = struct
  include File1_intf
end

module File3 = struct
  open File1

  let ok : type1 -> type1 = fun { nat } -> { nat = 0 }
  let ko { nat (*Unbound record field nat*) } = { nat = 0 }
end
Run Code Online (Sandbox Code Playgroud)

我期望“未绑定记录字段”,但我想知道为什么添加类型装饰会将字段“nat”纳入范围。

oct*_*ron 5

方程File1.type1=File_intf.type1在 ok 函数的范围内。因此,类型定向消歧可以扩展 的缩写File1.type1来消歧字段nat

编译器确实警告您该字段nat本身不在范围内:

Warning 40: this record of type File1_intf.type1 contains fields
that are not visible in the current scope: nat.
They will not be selected if the type becomes unknown.
Run Code Online (Sandbox Code Playgroud)