OCaml - 来自类型别名的混淆(警告40)

use*_*881 2 warnings ocaml type-alias

我不明白为什么OCaml无法弄清楚这里没有混淆的空间:下面的aint不能是A的另一个.

module A = struct
  type test = Graphics.status
end

module type ASIG = sig
  type test = A.test
  val atest : test 
end

module Func (H : ASIG) = struct
  let _ = let open H in atest.key 
end
Run Code Online (Sandbox Code Playgroud)

然而,它提出了

Warning 40: key was selected from type Graphics.status.
It is not visible in the current scope, and will not 
be selected if the type becomes unknown.
Run Code Online (Sandbox Code Playgroud)

如何在不禁用警告的情况下告诉它"没关系"?

我知道我可以通过打开解决它A.但是,如果H将其自己的函数和类型定义为与A类似但不相等 - 则会产生不必要的冲突.我也知道我可以复制定义,但这会破坏类型别名的目的,并涉及许多不必要的代码重复.也许没有解决方案,但我想知道为什么OCaml在这个上如此盲目愚蠢:类型别名应该也意味着构造函数和记录字段别名,不应该吗?

ghi*_*esZ 5

您可以在引用字段时在本地打开定义原始类型的模块key,如下所示:

module A = struct
  type test = Graphics.status
end

module type ASIG = sig
  type test = A.test
  val atest : test 
end

module Func (H : ASIG) = struct
  let _ = let open H in atest.Graphics.key 
end
Run Code Online (Sandbox Code Playgroud)

或者,如果您需要引用几个字段:
let _ = let open H in Graphics.(atest.key, atest.button)