From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id QAA22990 for caml-red; Fri, 23 Jun 2000 16:13:37 +0200 (MET DST) 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 KAA17309 for ; Thu, 22 Jun 2000 10:42:32 +0200 (MET DST) Received: from pst.polyspace.com (polyspace.com [193.51.203.61]) by concorde.inria.fr (8.10.0/8.10.0) with ESMTP id e5M8gVP08946 for ; Thu, 22 Jun 2000 10:42:31 +0200 (MET DST) Received: from localhost (rinderkn@localhost) by pst.polyspace.com (8.9.1b+Sun/8.9.1) with ESMTP id KAA16042; Thu, 22 Jun 2000 10:41:51 +0200 (MET DST) Date: Thu, 22 Jun 2000 10:41:50 +0200 (MET DST) From: Christian Rinderknecht To: David=?iso-8859-1?q?_Mentr=E9?= cc: caml-list@inria.fr Subject: Re: How to cleanly encode "quasi-constants"? In-Reply-To: Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: QUOTED-PRINTABLE Sender: weis@pauillac.inria.fr Hi David, I think it's worth reading the caml-list thread "one-time initialization", starting at http://caml.inria.fr/caml-list/1005.html. Personnally, in the particular situation you mention, I would do the following. In a Second(ary) module you define a functor taking as argument a module with all the globals you need. second.mli ---------- module type S =3D sig type type0 =3D ... val const0 : type0 end module Run (Args : S) :=20 sig=20 val entry_point : unit -> unit end second.ml --------- module type S =3D sig type type0 =3D ... val const0 : type0 ... end module Run =3D functor (M : S) -> struct open M ... (* From here you handle "real" constants" [const0] etc. *) let entry_point () =3D ... end By the way, note that in OCaml, contrary to SML, you cannot define a functor at top-level (this would require extra syntax), i.e. whose name is mapped to a file name. Now in your Main module: main.ml ------- module Args =3D struct type type0 =3D ... let quasi_const0 : (type0 option) ref =3D ref (None) ... let _ =3D Arg.parse .... (* Initialization by side-effects of [quasi_const0] etc. *) let const0 =3D=20 match !quasi_const0 with None -> failwith "Missing arg" (* Or whatever *) | Some (v) -> v ... end module Go =3D Second.Run (Args) let _ =3D Go.entry_point () Note that name [Go] is necessary (Second.Run(Args).enty_point() does not work). Hope this helps, Christian -------------------------------------------------------------------- Christian Rinderknecht Christian.Rinderknecht@polyspace.com PolySpace Technologies Tel: 04.76.61.54.17 c/o INRIA Fax: 04.76.61.54.09 655, Av. de l'Europe http://www.polyspace.com/ F-38330 Montbonnot St Martin On 20 Jun 2000, David Mentr=E9 wrote: > In my program, I have variables that can only be modified once > (potentially at initialization time after parsing command line and done > some computation) and then are never modified for a very long time (rest > of program execution).