From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id VAA13633; Mon, 24 Sep 2001 21:53:15 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id VAA13629 for ; Mon, 24 Sep 2001 21:53:14 +0200 (MET DST) Received: from villosa.wanadoo.fr (smtp-abo-1.wanadoo.fr [193.252.19.122]) by concorde.inria.fr (8.11.1/8.10.0) with ESMTP id f8OJrDX03410 for ; Mon, 24 Sep 2001 21:53:13 +0200 (MET DST) Received: from debian (213.56.54.233) by villosa.wanadoo.fr; 24 Sep 2001 21:53:13 +0200 Received: from moi by debian with local (Exim 3.32 #1 (Debian)) id 15lbnB-0000E1-00 for ; Mon, 24 Sep 2001 21:53:25 +0200 To: caml-list@inria.fr Subject: Re: [Caml-list] Haskell features in O'Caml References: <4F8477CFC03A71499AD8DDA428F5E114037723@basecamp.mchp.siemens.de> From: Remi VANICAT Date: 24 Sep 2001 21:53:25 +0200 In-Reply-To: <4F8477CFC03A71499AD8DDA428F5E114037723@basecamp.mchp.siemens.de> Message-ID: <87elow1i2y.dlv@wanadoo.fr> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.0.105 MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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