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 RAA01194; Thu, 12 Aug 2004 17:06:40 +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 RAA29853 for ; Thu, 12 Aug 2004 17:06:39 +0200 (MET DST) Received: from relaissmtp.ens-lyon.fr (pluvier.ens-lyon.fr [140.77.167.5]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i7CF6cRM009943 for ; Thu, 12 Aug 2004 17:06:38 +0200 Received: from mouette.ens-lyon.fr ([140.77.167.4]) by relaissmtp.ens-lyon.fr with esmtp (Exim 3.35 #1 (Debian)) id 1BvHA6-0004eL-00 for ; Thu, 12 Aug 2004 17:06:38 +0200 Received: by mouette.ens-lyon.fr (Postfix, from userid 33) id 74FD73C61C2; Thu, 12 Aug 2004 17:06:38 +0200 (CEST) To: caml-list@inria.fr Subject: Re: [Caml-list] Managing a polymorphic environment Message-ID: <1092323198.411b877e22214@mouette.ens-lyon.fr> Date: Thu, 12 Aug 2004 17:06:38 +0200 (CEST) From: Jean-Baptiste Rouquier References: In-Reply-To: MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: IMP/PHP IMAP webmail program 2.2.6 X-Originating-IP: 68.40.185.95 X-Miltered: at concorde with ID 411B877E.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 ens-lyon:01 quoting:01 pons:01 pons:01 etu:99 pretty-print:01 100.0:01 meets:99 foo:01 foo:01 coerced:01 ens-lyon:01 fernandez:01 fernandez:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk Quoting Diego Olivier Fernandez Pons : > 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 = () I'm finishing a lib to handle configuration files, which meets the same kind of problem : one would like pretty print (and read back) the values, but handle them in type safe way inside the programme. I'm using objects and I think it can solve your problem : have a class Env.foo that has a virtual method print (and any other method to implement the functions you want in Env), and have classes foo_int and foo_float that inherit from it. Then your code will be written let x = new foo_int 10 "the number of elements in the knapsack" Env.add x (*x is coerced to foo, we forget it's an int*) let c = new foo_float "the total cost of the knapsack" Env.add c x#print c#print I can send you my code if you want more details. Jean-Baptiste. http://perso.ens-lyon.fr/jean-baptiste.rouquier ------------------- 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