Ich bin neu in OCaml und ich bin etwas verwirrt über Module.OCaml: Unbound Module.Function Wert
Ich habe versucht, einen wirklich einfachen Test zu implementieren, aber ich kann es nicht kompilieren kann ...
Hier sind die Dateien (ich bin auf Linux by the way):
main.ml
let main() =
if ((Array.length Sys.argv) > 2 && int_of_string Sys.argv.(1) > 1 && int_of_string Sys.argv.(2) > 1)
then
begin
Printf.printf "Args = %d && %d\n" (int_of_string Sys.argv.(1)) (int_of_string Sys.argv.(2));
Laby.initLaby (int_of_string Sys.argv.(1)) (int_of_string Sys.argv.(2))
end
else
Printf.printf "Usage : ./test x y n"
let _ = main()
Laby.ml
let initLaby (x : int) (y : int) =
let testCell = Cell.initCell 0 1 in
begin
Printf.printf "Init Laby with X(%d)/Y(%d)\n" x y;
Cell.printCell testCell;
end
Cell.ml
module type CELL =
sig
type t
val initCell : int -> int -> t
val printCell : t -> unit
end
module Cell : CELL =
struct
type t = (int * int)
let initCell (x : int) (y : int) =
(x, y)
let printCell (x, y) =
Printf.printf "Cell -> X(%d)/Y(%d)\n" x y
end
Cell.mli
module type CELL =
sig
type t
val initCell : int -> int -> t
val printCell : t -> unit
end
module Cell : CELL
Und hier ist die Makefile:
NAME = test
ML = Cell.ml \
Laby.ml \
main.ml
MLI = Cell.mli
CMI = $(MLI:.mli=.cmi)
CMO = $(ML:.ml=.cmo)
CMX = $(ML:.ml=.cmx)
OCAMLDPE = ocamldep
CAMLFLAGS = -w Aelz -warn-error A
OCAMLC = ocamlc $(CAMLFLAGS)
OCAMLOPT = ocamlopt $(CAMLFLAGS)
OCAMLDOC = ocamldoc -html -d $(ROOT)/doc
all: .depend $(CMI) $(NAME)
byte: .depend $(CMI) $(NAME).byte
$(NAME): $(CMX)
@$(OCAMLOPT) -o [email protected] $(CMX)
@echo "[OK] $(NAME) linked"
$(NAME).byte: $(CMO)
@$(OCAMLC) -o [email protected] $(CMO)
@echo "[OK] $(NAME).byte linked"
%.cmx: %.ml
@$(OCAMLOPT) -c $<
@echo "[OK] [$<] builded"
%.cmo: %.ml
@$(OCAMLC) -c $<
@echo "[OK] [$<] builded"
%.cmi: %.mli
@$(OCAMLC) -c $<
@echo "[OK] [$<] builded"
documentation: $(CMI)
@$(OCAMLDOC) $(MLI)
@echo "[OK] Documentation"
re: fclean all
clean:
@/bin/rm -f *.cm* *.o .depend *~
@echo "[OK] clean"
fclean: clean
@/bin/rm -f $(NAME) $(NAME).byte
@echo "[OK] fclean"
.depend:
@/bin/rm -f .depend
@$(OCAMLDPE) $(MLI) $(ML) > .depend
@echo "[OK] dependencies"
Hier ist der Ausgang des Makefile ist:
[OK] dependencies
[OK] [Cell.mli] builded
[OK] [Cell.ml] builded
File "Laby.ml", line 3, characters 17-30:
Error: Unbound value Cell.initCell
Makefile:47: recipe for target 'Laby.cmx' failed
make: *** [Laby.cmx] Error 2
Ich denke, es ist ein Übersetzungsfehler, da sie die Zellen-Modul nicht gefunden scheint, aber ich kann nicht machen es funktioniert ... Was mache ich falsch, und wie kann ich es beheben?
Danke, es funktioniert! Gibt es eine Möglichkeit, diese doppelte (abgesehen von offenen Zelle) zu vermeiden? Und Sie haben Recht, die Dateinamen sollten in Kleinbuchstaben sein, ich vermasselt mit C++ ... (Und das Makefile ist aus meiner Schulstunde Quellen, ich sah nicht das falsche Englisch ...) – SomeRaven
ja, du kann die Datei cell.ml direkt den Körper des Moduls Cell enthalten, und cell.mli enthält den Rumpf der Signatur CELL. (d.h. ohne struct..end bzw. sig..end). Der einzige Unterschied besteht darin, dass Sie dem Modultyp nicht explizit einen Namen (CELL) geben. Ein solcher Name wird normalerweise nur benötigt, wenn CELL als Eingabe für einen Funktor dient. deutsch: 'builded' -> 'gebaut'. – user3240588
Oh ok, ich werde das versuchen! Vielen Dank ! (und für die Korrektur falscher Englisch ^^ ') – SomeRaven