caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Jacques GARRIGUE <garrigue@kurims.kyoto-u.ac.jp>
To: basile.starynkevitch@inria.fr
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] marshalling polymorphic variants
Date: Tue, 29 Jun 2004 17:54:13 +0900 (JST)	[thread overview]
Message-ID: <20040629.175413.36858460.garrigue@kurims.kyoto-u.ac.jp> (raw)
In-Reply-To: <20040629075532.GA28862@bourg.inria.fr>

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


  reply	other threads:[~2004-06-29  8:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-28 21:02 henri dubois-ferriere
2004-06-29  7:55 ` Basile Starynkevitch [local]
2004-06-29  8:54   ` Jacques GARRIGUE [this message]
2004-06-29  8:45 ` Richard Jones
2004-06-29 17:50   ` Alex Baretta
2004-06-29 21:54     ` henri dubois-ferriere

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040629.175413.36858460.garrigue@kurims.kyoto-u.ac.jp \
    --to=garrigue@kurims.kyoto-u.ac.jp \
    --cc=basile.starynkevitch@inria.fr \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).