Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] marshalling polymorphic variants
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Jacques GARRIGUE <garrigue@k...>
Subject: Re: [Caml-list] marshalling polymorphic variants
From: "Basile Starynkevitch [local]" <basile.starynkevitch@inria.fr>
> 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 = <fun>

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