【发布时间】:2015-07-06 15:28:10
【问题描述】:
我有一个模块接口
module type Enum = sig
type t
val toInt : t -> int
val fromInt : int -> t
end
然后我有一个模块
module Navigability : Enum = struct
type t=
AB
| BA
| Both
| None
let toInt = function
| BA -> -65536
| Both -> -1
| None -> 0
| AB -> 65535
let fromInt = function
| -65536 -> BA
| -1 -> Both
| 0 -> None
| 65535 -> AB
| _ -> None
end
添加以下函数后,代码无法编译:
let fun = function
| Navigability.t.BA -> false
| Navigability.t.Both -> true
| Navigability.t.None -> false
| Navigability.t.AB -> true
如果我把它放在模块内并取消接口,它就可以工作。
谁能告诉我为什么以及如何?
【问题讨论】:
-
附带说明,
fun是 OCaml 关键字,不应用作函数名。 -
@PatJ 啊,我在这里发帖的时候把名字改成了fun 谢谢