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 TAA06547; Thu, 12 Aug 2004 19:05:16 +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 TAA04065 for ; Thu, 12 Aug 2004 19:05:15 +0200 (MET DST) Received: from mail1.speakeasy.net (mail1.speakeasy.net [216.254.0.201]) by nez-perce.inria.fr (8.12.10/8.12.10) with ESMTP id i7CH5DmL031493 for ; Thu, 12 Aug 2004 19:05:14 +0200 Received: (qmail 23594 invoked from network); 12 Aug 2004 17:05:12 -0000 Received: from shell2.speakeasy.net ([69.17.110.71]) (envelope-sender ) by mail1.speakeasy.net (qmail-ldap-1.03) with AES256-SHA encrypted SMTP for ; 12 Aug 2004 17:05:12 -0000 Date: Thu, 12 Aug 2004 10:05:11 -0700 (PDT) From: brogoff To: Diego Olivier Fernandez Pons cc: caml-list@inria.fr Subject: Re: [Caml-list] Managing a polymorphic environment In-Reply-To: Message-ID: References: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Miltered: at nez-perce with ID 411BA349.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; brogoff:01 brogoff:01 caml-list:01 howdy:01 200105:01 intern:01 val:01 atom:01 intern:01 val:01 atom:01 100.0:01 printf:01 printf:01 pons:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Howdy, I'm sure I'm completely misunderstanding your problem, but how about referring to the environment variables by by strings and attaching properties to them, using the property list trick that Xavier described here a few years ago http://caml.inria.fr/archives/200105/msg00175.html Then we get something like this # let x = intern "x";; val x : atom = {name = "x"; properties = []} # let c = intern "c";; val c : atom = {name = "c"; properties = []} # let int_property = (new_property() : int property);; val int_property : int property = {contents = None} # let string_property = (new_property() : string property);; val string_property : string property = {contents = None} # let float_property = (new_property() : float property);; val float_property : float property = {contents = None} # put_property x int_property 10;; - : unit = () # put_property x string_property "the number of elements in the knapsack";; - : unit = () # put_property c float_property 100.0;; - : unit = () # put_property c string_property "the total cost of the knapsack";; - : unit = () # let print_int a = Printf.printf "%s is %d\n" (get_property a string_property) (get_property a int_property);; val print_int : atom -> unit = # print_int x;; the number of elements in the knapsack is 10 - : unit = () # print_int c;; Exception: Not_found. # let print_float a = Printf.printf "%s is %g\n" (get_property a string_property) (get_property a float_property);; val print_float : atom -> unit = # print_float c;; the total cost of the knapsack is 100 - : unit = () # print_float x;; Exception: Not_found. I think you can modify the basic approach to be slightly more suitable to your task, but that comes pretty close. -- Brian On Thu, 12 Aug 2004, Diego Olivier Fernandez Pons wrote: > Bonjour, > > Here is an other type related problem : > > I would like to have an environment that associates strings to values > > let x = ... > Env.add x "the number of elements in the knapsack" > let c = ... > Env.add c "the total cost of the knapsack" > > > The idea is of course to be able to pretty-print the result > > # Env.print_int x;; > the number of elements in the knapsack is 10 - : unit = () > # Env.print_float c > the total cost of the knapsack is 100.0 - : unit = () > > > Env data structure can be based on equallity only since the user is > supposed to add comments only for the most important variables. The > simplest idea is once more hashing all variables. But one would like > to avoid collisions. > > > Any suggestion ? > > Diego Olivier > > ------------------- > 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 > ------------------- 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