OCaml - 签名、模块和类型
OCaml - Signatures, Modules and Types
我有一个关于签名类型的基本问题。如果我有两个 ocaml 文件,例如:
istr.ml
type t = int
let get_string f v = f v
和fstr.ml
type t = float
let get_string f v = f v
和签名
stri.mli
module type STR =
sig
type t
val get_string: (t -> string) -> t -> string
end
上面签名中的类型t是什么?它是多态的吗?
它是一种抽象类型,隐藏了实现,不让用户直接使用。见 module system or RWO
但我不确定您当前的示例能否正常工作,因为您的代码示例似乎不在模块中。
我有一个关于签名类型的基本问题。如果我有两个 ocaml 文件,例如:
istr.ml
type t = int
let get_string f v = f v
和fstr.ml
type t = float
let get_string f v = f v
和签名
stri.mli
module type STR =
sig
type t
val get_string: (t -> string) -> t -> string
end
上面签名中的类型t是什么?它是多态的吗?
它是一种抽象类型,隐藏了实现,不让用户直接使用。见 module system or RWO
但我不确定您当前的示例能否正常工作,因为您的代码示例似乎不在模块中。