我有一個地方的地圖定義ocaml的:在MLI文件
module CtxMap = Map.make(struct type t = int let compare = compare end)
文件context.ml與類型的函數map_get
導出型CtxMap.key -> 'a CtxMap.t -> 'a
如何添加CtxMap聲明context.mli文件? 因爲mli文件不能包含代碼,所以我無法找到一種方法。
我有一個地方的地圖定義ocaml的:在MLI文件
module CtxMap = Map.make(struct type t = int let compare = compare end)
文件context.ml與類型的函數map_get
導出型CtxMap.key -> 'a CtxMap.t -> 'a
如何添加CtxMap聲明context.mli文件? 因爲mli文件不能包含代碼,所以我無法找到一種方法。
module CtxMap : Map.S with type key = int
在設有OCaml中的map.ml
文件,對於仿函數簽名的名字是S
,並且key
是要公開向外界模塊的唯一抽象類型。
僅供參考,你總是可以做:
ocamlc -i -c context.ml
輸出默認.mli
文件到標準輸出。這個問題(在你的情況下)唯一的問題是它擴大了地圖的簽名。
您需要添加`-c`來避免添加所有依賴關係 - 此選項編譯但不鏈接。 – nlucaroni 2011-02-02 22:36:52