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 EAA26939; Sat, 16 Feb 2002 04:16:39 +0100 (MET) 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 EAA16215 for ; Sat, 16 Feb 2002 04:16:36 +0100 (MET) Received: from hotmail.com (f177.law8.hotmail.com [216.33.241.177]) by nez-perce.inria.fr (8.11.1/8.11.1) with ESMTP id g1G3GZv25312 for ; Sat, 16 Feb 2002 04:16:35 +0100 (MET) Received: from mail pickup service by hotmail.com with Microsoft SMTPSVC; Fri, 15 Feb 2002 19:16:30 -0800 Received: from 68.82.53.91 by lw8fd.law8.hotmail.msn.com with HTTP; Sat, 16 Feb 2002 03:16:30 GMT X-Originating-IP: [68.82.53.91] From: "Ryan Tarpine" To: caml-list@inria.fr Subject: Re: [Caml-list] Another q about many types Date: Fri, 15 Feb 2002 22:16:30 -0500 Mime-Version: 1.0 Content-Type: text/plain; format=flowed Message-ID: X-OriginalArrivalTime: 16 Feb 2002 03:16:30.0695 (UTC) FILETIME=[54324770:01C1B698] Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk >From: Martin Jambon >To: Ryan Tarpine >Subject: Re: [Caml-list] Another q about many types >Date: Fri, 15 Feb 2002 11:21:29 +0100 (CET) >... >Maybe something like this: > >exception E of exn >... >exception E_1 of t1 >... >exception E_2 of t2 >... > >try ... with > E e -> > match e with > E_1 x1 -> x1 > | E_2 x2 -> some_conversion_to_t1 x2 > > >Martin I though this was a great idea, but then I hit another roadblock. You couldn't see this was coming from the info I've given so far, of course :) In actuality, my objects are more like this: type 'a my_object = { object_ivs : 'a my_object my_table; object_data : 'a ref } object_ivs stores the object's independent variables (my_table is basically an association table, where a name lookup finds a variable; ignore it). object_data stores the object's primitive, the actual OCaml data (int, float, string, etc.), in a polymorphic variant. Instances of the integer class, for example, will have something like (`PInteger x) stored in object_data. object_ivs stores whole other objects, not primitives. A user-defined class, for example, would have something like (`PNone) in object_data and all member variables in object_ivs. Unfortunately, this means that in order to raise an exception with an object of type my_object, not only its own object_data but the data of all the variables stored in object_ivs must be of the same type. I've tried making the exception type like this: type allowed_exc = [ `PNone | `PInteger of int | `PFloat of float | `PString of string ];; exception EError of allowed_exc my_object;; to make the type of allowed exceptions somewhat lax. But, given a single ('a my_object), how can I coerce it to an (allowed_exc my_object) if possible? It has to recursively coerce all the variables in object_ivs. I've never done coercion at all before. Thanks in advance (everyone's helped me so much already!), Ryan Tarpine, rtarpine@hotmail.com "To err is human, to compute divine. Trust your computer but not its programmer." - Morris Kingston Ryan Tarpine, rtarpine@hotmail.com "To err is human, to compute divine. Trust your computer but not its programmer." - Morris Kingston _________________________________________________________________ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp. ------------------- 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