我可以寫我自己的擴展List
模塊的OCaml的,通過定義文件lib.ml
和包括List
模塊:如何延長Map.Make仿
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
。
有誰知道怎麼辦呢?