caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Miles Egan <miles@caddr.com>
To: caml-list@inria.fr
Subject: Re: [Caml-list] hash_variant anomalies
Date: Tue, 3 Jul 2001 08:15:40 -0700	[thread overview]
Message-ID: <20010703081540.A58338@caddr.com> (raw)
In-Reply-To: <20010703094210.A15237@pauillac.inria.fr>; from Xavier.Leroy@inria.fr on Tue, Jul 03, 2001 at 09:42:10AM +0200

On Tue, Jul 03, 2001 at 09:42:10AM +0200, Xavier Leroy wrote:
> 2- Owing to the Caml encoding of integers (integer N is represented by
> the bit pattern for 2N+1), when the manual says that constant
> constructors are numbered starting from 0, it really means that the
> constant constructors are represented by the representation of 0, the
> representation of 1, etc, that is, by 1, 3, etc.

Ok.  That makes sense.  I think this language is a bit confusing:

"""
the hash value for a variant constructor named, say, VConstr is
hash_value("VConstr").

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

What wasn't clear to me is that both sentences are referring to polymorphic
variants, when they seem to be comparing the properties of normal variants and
polymorphic variants.  Chapter 2 of the manual uses the term "variant" to refer to
both kinds of variants, so when I see a sentence describing a variant "VConstr"
and a variant "`VConstr" I assume it's referring to both types.

I guess the upshot of all this is that it's much easier to map polymorphic
variants to C constants because there's no easy way to calculate the integer
value of a normal variant without knowing it's position in the variant
declaration.  The integer value of a polymorphic variant can be computed
directly from its name alone.

Overall I have to say writing ocaml-c interfaces is pretty easy.  Mapping long
lists of c enums and defines to ocaml variants seems to be one of the more
tedious tasks.

-- 
miles
-------------------
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


  reply	other threads:[~2001-07-03 15:15 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-07-03  1:02 Miles Egan
2001-07-03  2:18 ` Chris Quinn
2001-07-03  7:42 ` Xavier Leroy
2001-07-03 15:15   ` Miles Egan [this message]
2001-07-04  0:19     ` Jacques Garrigue
2001-07-05  5:58       ` Miles Egan

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=20010703081540.A58338@caddr.com \
    --to=miles@caddr.com \
    --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).