我编写了以下两个文件,虽然它可以工作,但代码会重复这些长类型声明,这感觉很奇怪。另一方面,如果我删除任一模块类型声明,则代码将不再编译。
这种东西有更合适的写法吗?或者在 .mli 和 .ml 文件中重复这些类型声明是否正确?
设置.mli
module type Element = sig
type t
val create : 'a -> t
val compare : t -> t -> int
val to_string : t -> string
end
module type Set = sig
type t
val empty : unit -> t
end
module Make : functor (M : Element) -> Set with type t = M.t list
设置.ml
module type Element = sig
type t
val create : 'a -> t
val compare : t -> t -> int
val to_string : t -> string
end
module type Set = sig
type t
val empty : unit -> t
end
module Make (M:Element) = struct
type t = M.t list
let emtpy () = []
end