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 KAA15110; Tue, 29 Jun 2004 10:54:18 +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 KAA15099; Tue, 29 Jun 2004 10:54:17 +0200 (MET DST) Received: from kurims.kurims.kyoto-u.ac.jp (kurims.kurims.kyoto-u.ac.jp [130.54.16.1]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i5T8sESH028841; Tue, 29 Jun 2004 10:54:15 +0200 Received: from localhost (suiren.kurims.kyoto-u.ac.jp [130.54.16.25]) by kurims.kurims.kyoto-u.ac.jp (8.9.3p2-20030924/3.7W) with ESMTP id RAA03924; Tue, 29 Jun 2004 17:54:13 +0900 (JST) Date: Tue, 29 Jun 2004 17:54:13 +0900 (JST) Message-Id: <20040629.175413.36858460.garrigue@kurims.kyoto-u.ac.jp> To: basile.starynkevitch@inria.fr Cc: caml-list@inria.fr Subject: Re: [Caml-list] marshalling polymorphic variants From: Jacques GARRIGUE In-Reply-To: <20040629075532.GA28862@bourg.inria.fr> References: <20040629075532.GA28862@bourg.inria.fr> X-Mailer: Mew version 4.0.64 on Emacs 21.2 / Mule 5.0 (SAKAKI) Mime-Version: 1.0 Content-Type: Text/Plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 40E12E36.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 marshalling:01 jacques:01 basile:01 basile:01 2004:99 marshalling:01 casts:01 casts:01 hash:01 jacques:01 compiler:01 variants:01 variants:01 garrigue:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk From: "Basile Starynkevitch [local]" > On Mon, Jun 28, 2004 at 11:02:25PM +0200, henri dubois-ferriere wrote: > > > in the simple case below, it is possible to marshal out a ([`A | `B] > > list), and then read it back as a [> `A | `B | `C] list. > > > I think that yes, because: > > 1. marshalling don't care about type casts (hence you can shot in > your leg if you abuse it) and is not type safe. > > 2. polymorphic variants are (IIRC) represented by using the hashcode > of their name, so `A is always `A in any polymorphic variant > context. Actually in this case there are no casts involved, as you can already convert an [`A | `B] list into an [> `A | `B | `C] list. # fun x -> (x : [`A | `B] list :> [> `A | `B | `C] list);; - : [ `A | `B ] list -> [> `A | `B | `C ] list = So, yes, this is safe, and intended to stay so, even between different versions of the compiler (as long as we don't change the hash function, and there is very little reason to do so.) Jacques Garrigue ------------------- 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