2016-08-14 2 views
2

Hier habe ich eine Datei set.ml mit einem Modul namens IntSet. Wie beziehe ich mich auf das Modul IntSet in der entsprechenden Schnittstellendatei set.mli?OCaml beziehen sich auf Modul in ml Datei innerhalb mli

module IntSet = struct 
    type t = int list;; 
    let empty = [];; 
    let rec is_member key = function 
    | [] -> false 
    | (x::xs) -> (
     if x = key then true 
     else is_member key xs 
    );; 
end;; 

let join xs ys = xs @ ys;; 

Hier ist set.mli

val join : IntSet.t -> IntSet.t -> IntSet.t

Wenn ich versuche, es zu kompilieren, ich erhalte eine Fehlermeldung behauptet, dass das Modul IntSet ungebunden ist.

% corebuild set.native 
+ ocamlfind ocamlc -c -w A-4-33-40-41-42-43-34-44 -strict-sequence -g -bin-annot -short-paths -thread -package core -ppx 'ppx-jane -as-ppx' -o set.cmi set.mli 
File "set.mli", line 1, characters 11-19: 
Error: Unbound module IntSet 
Command exited with code 2. 
Hint: Recursive traversal of subdirectories was not enabled for this build, 
    as the working directory does not look like an ocamlbuild project (no 
    '_tags' or 'myocamlbuild.ml' file). If you have modules in subdirectories, 
    you should add the option "-r" or create an empty '_tags' file. 

    To enable recursive traversal for some subdirectories only, you can use the 
    following '_tags' file: 

     true: -traverse 
     <dir1> or <dir2>: traverse 

Compilation unsuccessful after building 3 targets (1 cached) in 00:00:00. 

Wie aussetzen ich ein Modul definiert in set.ml so kann ich es in Definitionen verwenden?

Antwort

2

Ich änderte set.mli dazu und der Compiler scheint glücklich:

module IntSet : sig type t end 
val join : IntSet.t -> IntSet.t -> IntSet.t 

Es wahrscheinlich mehr Arbeit ist, die Dinge nutzbar zu machen. Es gibt keine Möglichkeit, einen Wert vom Typ IntSet.t zum Beispiel zu machen.

Verwandte Themen