Ocaml 将函子保存在单独的文件中
我有一个函数化的图形类型Ocaml 将函子保存在单独的文件中,ocaml,functor,Ocaml,Functor,我有一个函数化的图形类型 module type GRAPH_LABELS = sig type label end module type GRAPH = sig type label type graph val init : int -> graph val size : graph -> int val insert_directed_edge : gra
module type GRAPH_LABELS =
sig
type label
end
module type GRAPH =
sig
type label
type graph
val init : int -> graph
val size : graph -> int
val insert_directed_edge : graph -> int -> int -> label -> unit
val insert_edge : graph -> int -> int -> label -> unit
val neighbours : graph -> int -> (int*label) list
end
module Graph = functor (L : GRAPH_LABELS) ->
struct
(* implementation which matches GRAPH *)
end
我想把它单独归档。我将所有内容都放入graph.ml
。当我用函子创建一个模块时
module VoidLabels = struct type label = unit end
module Gr = Graph (VoidLabels)
我得到一个错误:
This module is not a functor; it has type
sig
module type GRAPH_LABELS = sig type label end
module type GRAPH = (* ... *)
我应该如何正确地执行它?我很确定您应该拥有
模块Gr=Graph.Graph(VoidLabels)
以及我应该如何修改源代码以使我的呼叫合法?在文件开头添加open Graph
。不能将函子作为顶级名称,因此没有其他方法。