caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Bruno Daniel <bruno.daniel@gmx.net>
To: caml-list@yquem.inria.fr
Subject: Representation of different polymorphic variants guaranteed to be different?
Date: Wed, 8 Jul 2009 20:35:27 +0200	[thread overview]
Message-ID: <20090708183527.GC3432@colinux> (raw)

Dear OCaml developers,

I'm trying to understand the representation of polymorphic variants in OCaml
and I'm a bit worried about possible problems. Section 18.3.6 of the
OCaml 3.11 reference manual reads:

"[...] The variant value `VConstr is represented by hash_variant("VConstr").
The variant value `VConstr(v) is represented by a block of size 2 and tag 0,
with field number 0 containing hash_variant("VConstr") and field number 1
containing v."

I take it from the source code of caml_hash_variant in
ocaml-3.11.1_src/asmrun/hash.c and hash_variant in
ocaml-3.11.1_src/typing/btype.ml that hash_variant returns an OCaml 31-bit
integer value, i.e. there is only room for at most 2147483648 different
polymorphic variants, but even with identifiers composed of only 7 characters
chosen from 26 letters one could easily construct  8031810176 different
polymorphic variant constructors.

How is it ensured that I get a <> b for a and b created as polymorphic
variants from two different identifiers? Will pattern matching give wrong
results if I accidentally choose two different identifiers translated to the
same internal representation?

The same applies to method names according to section 18.3.5:
"Since public method tags are hashed in the same way as variant tags, and
methods are functions taking self as first argument, if you want to do the method
call foo#bar from the C side, you should call:
callback(caml_get_public_method(foo, hash_variant("bar")), foo);".

I apologize if these questions have been answered before. I couldn't find any
discussion about them in the archives. Thank you very much for your help.

Best regards
  Bruno Daniel


             reply	other threads:[~2009-07-08 18:37 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-08 18:35 Bruno Daniel [this message]
2009-07-08 18:54 ` [Caml-list] " Eric Cooper
2009-07-08 19:32   ` Elnatan Reisner
2009-07-08 19:32   ` Bruno Daniel
2009-07-08 19:36   ` Frédéric van der Plancke

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=20090708183527.GC3432@colinux \
    --to=bruno.daniel@gmx.net \
    --cc=caml-list@yquem.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).