[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2001-09-24 (19:53) |
From: | Remi VANICAT <vanicat@l...> |
Subject: | Re: [Caml-list] Haskell features in O'Caml |
Christian.Schaller@cert.siemens.de writes: > > The correct answer might have been a reference to the module system. > > You can specify the type of a function either in a separate *.mli-file > > or in an explicit module declaration: > > > > # module M : sig > > val mul : int -> int -> int > > end = struct > > let mul a b = a * b > > end;; > > module M : sig val mul : int -> int -> int end > > # M.mul 2 3;; > > - : int = 6 > > # module N : sig > > val mul : int -> int -> int > > end = struct > > let mul a b = a *. b (* Arithmetic is monomorphic - no > > type classes *) > > end;; > > Signature mismatch: > > Modules do not match: > > [...] > > > > Unfortunately there seems to be a difference between explicit module > declaration as seen above and the separation of interface and > implementation. > > Since implementation is not automatically checked against the interface > (or did I get something wrong?), yes, you do: test.ml : let f x = x test.mli : val f : int -> float $ ocamlc -c test.ml I/O error: test.cmi: No such file or directory $ ocamlc -c test.mli $ ocamlc -c test.ml The implementation test.ml does not match the interface test.cmi: Values do not match: val f : 'a -> 'a is not included in val f : int -> float > you just load you implementation (or > compile it) without using (or compiling) the appropriate interface and there > will be no complaint about mismatch in signature and structure. > > I'd prefer the compiler/desktop automatically look for interface > definition while compiling/loading. > > One more or less off-topic question about interfaces: is there a way to > see the all what's inside a module when I'm opening it using "open" (like > "module M : sig val mul : int -> int -> int end" in above example)? yes : $ Module T = List module T : sig external length : string -> int = "%string_length" external get : string -> int -> char = "%string_safe_get" external set : string -> int -> char -> unit = "%string_safe_set" [...] external unsafe_fill : string -> pos:int -> len:int -> char -> unit = "fill_string" "noalloc" end -- Rémi Vanicat vanicat@labri.u-bordeaux.fr http://dept-info.labri.u-bordeaux.fr/~vanicat ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr