Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

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-24 (15:26)
From: Jean Yang <jeanyang@c...>
Subject: OCaml/C variant representation

  I'm having some trouble with variant representation in the OCaml/C

  According to the reference I found (, it seems like if
we have value v = variant VConstr(val), where val is some integer value,
should have Field(val, 0) == hash_variant("VConstr") and Int_val(Field(v, 0)
== val.  I don't seem to be understanding this correctly, since I am getting
Int_val(Field(v, 0)) == val.

  I have the following datatype declaration in my OCaml:
type newty = VConstr of int | ...
In the C implementation of OCaml function foo : newty -> int, I have
something like this;
  CAMLprim value foo (value v) {  ... }
In the body of this function I am looking at the fields of val.  Am I doing
something wrong here?


Jean Yang
Save us!  Think before you print.