我可以通过定义一个文件并包含模块List
来为 OCaml 模块编写自己的扩展:lib.ml
List
module List =
struct
include List
(* remove l x returns the list l without the first element x found or *)
(* returns l if no element is equal to x. *)
(* Elements are compared using ( = ). *)
let rec remove (l : 'a list) (x : 'a) : 'a list =
match l with
| [] -> []
| hd :: tl ->
if hd = x then
tl else
hd :: remove tl x
...
end
然后我可以调用Lib.List.remove ...
其他文件。
现在我想为Map.Make
仿函数编写我自己的扩展,我尝试了如下内容lib.ml
:
module Make (Ord : Map.OrderedType with type key = Ord.t) =
struct
include Map.Make(Ord)
let aaa = 1
end
但是,编译给出了错误Error: The signature constrained by 'with' has no component named key
。
有谁知道该怎么做?