【发布时间】:2018-04-13 14:24:16
【问题描述】:
我不明白为什么 OCaml 无法弄清楚这里没有混淆的余地:下面的 anint 除了 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
但是,它提高了
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.
如何在不禁用警告的情况下告诉它“很好”?
我知道我可以通过打开 A 来解决它。但是,如果 H 定义了自己的函数和类型,与 A 相似——但不等于——,那么它将产生不必要的冲突。我也知道我可以复制定义,但这违背了类型别名的目的,并且涉及大量不必要的代码重复。也许没有解决方案,但我想知道为什么 OCaml 在这个问题上如此愚蠢:类型别名应该也意味着构造函数和记录字段别名,不是吗?
【问题讨论】:
-
我现在澄清了一点,如果您认为不清楚,请告诉我。
-
请注意,从 OCaml 4.06.0(2017 年 11 月)开始,此警告默认关闭。
标签: ocaml warnings type-alias