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 CAA21936; Mon, 28 Jun 2004 02:54:34 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id CAA22276 for ; Mon, 28 Jun 2004 02:54:33 +0200 (MET DST) Received: from oola.is.scarlet.be (oola.is.scarlet.be [193.74.71.23]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i5S0sVEV020299 for ; Mon, 28 Jun 2004 02:54:32 +0200 Received: from (u195-95-92-150.goplanet.pi.be [195.95.92.150]) by oola.is.scarlet.be with ESMTP id i5S0sSf09289; Mon, 28 Jun 2004 02:54:28 +0200 Received: from poincare ([127.0.0.1] helo=localhost ident=trch) by poincare with esmtp (Exim 3.36 #1 (Debian)) id 1BekFv-0002jN-00; Mon, 28 Jun 2004 02:44:19 +0200 Date: Mon, 28 Jun 2004 02:44:18 +0200 (CEST) Message-Id: <20040628.024418.15565414.debian00@tiscali.be> To: gnu04@yahoo.com Cc: caml-list@inria.fr Subject: Re: [Caml-list] how to write interface file for these two files? From: Christophe TROESTLER In-Reply-To: <20040627230126.86986.qmail@web60905.mail.yahoo.com> References: <20040627230126.86986.qmail@web60905.mail.yahoo.com> Organization: None X-Spook: codes Croatian monarchist SWAT Mena AFSPC USCOI Fortezza electronic surveillance radar X-Mailer-URL: http://www.mew.org/ X-Operating-System: GNU/Linux (http://www.linux.org/) X-Blessing: Om Ah Hum Vajra Guru Pema Siddhi Hum X-Mailer: Mew version 4.0.61 on Emacs 21.3.1 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at nez-perce with ID 40DF6C47.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 troestler:01 tiscali:99 ocamlc:01 mli:01 ocamlc:01 val:01 val:01 chris:01 christophe:01 explicitely:01 int:01 int:01 discard:02 wrote:03 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Sun, 27 Jun 2004, Gu Nu wrote: > > I have a question on writing the interface file. Just use the output of "ocamlc -i file.ml" as a first version (this, in fact, is just the interface you get if no .mli file is present). You can of course then refine it, not exporting certain values, making certain types abstract... > A.ml > > type t = { x: int; y: int};; > let f c = c.x + c.y;; $ ocamlc -i a.ml type t = { x : int; y : int; } val f : t -> int > B.ml > > let val = {A.x =1 ; A.y = 2};; > A.f val;; > open A;; > f val;; Note that "val" is a reserved keyword -- you cannot use it as a variable name. Also, I think it is not nice to use ";;" to discard a returned value. Rather say it explicitely with "let _ =". That gives let pt = {A.x = 1 ; A.y = 2} let _ = A.f pt open A let _ = f pt $ ocamlc -i b.ml val pt : A.t The values that are not given a name are not present in the signature -- pretty natural, isn't it. Hope it helps, ChriS ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners