English version
Accueil     À propos     Téléchargement     Ressources     Contactez-nous    

Ce site est rarement mis à jour. Pour les informations les plus récentes, rendez-vous sur le nouveau site OCaml à l'adresse ocaml.org.

Browse thread
OCaml/C variant representation
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: 2010-02-28 (16:22)
From: Sylvain Le Gall <sylvain@l...>
Subject: Re: OCaml/C variant representation
On 28-02-2010, Jianzhou Zhao <jianzhou@seas.upenn.edu> wrote:
> On Wed, Feb 24, 2010 at 11:42 AM, Sylvain Le Gall <sylvain@le-gall.net> wrote:
>> On 24-02-2010, Jean Yang <jeanyang@csail.mit.edu> wrote:
>> Please have a look at:
>> http://caml.inria.fr/mantis/view.php?id=4803
>> This section is misleading. You should use hash_variant for `VConstr.
>> In your case VConstr of int will be Block with size = 1 and tag = 0;
>> first non-constant constructor and first field contains Value_int(...)
> If I am creating an OCaml variant (string option) from C, say using 'alloc',
> does it matter which tag I am using for 'some'? Can it be only tag 0?
> I was looking at LLVM OCamling bindings, sometimes the 'some' is
> also of 'tag 1', which confused me.

I think it is an error, but since there is only one possibility in the
case of Some, maybe it is not important (i.e. you can distingish between
the two variant None | Some just looking at the fact there are block or

> If my variant is A | B | C of int | D of int, does C have to start from tag 0?
> and D must be 1? Similarly, does A have to be assigned into Val_int(0),
> and B is from 1?

Yes. At least this is what I understand from section "18.3.4 Concrete
types" of the OCaml manual. As a matter of fact, I never had problems
following this convention before. 

Sylvain Le Gall