Hello, On 24-02-2010, Jean Yang <jeany...@csail.mit.edu> wrote: > Hello, > > I'm having some trouble with variant representation in the OCaml/C > interface. > > According to the reference I found ( > http://caml.inria.fr/pub/docs/manual-ocaml/manual032.html), 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? >
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(...) Regards Sylvain Le Gall _______________________________________________ Caml-list mailing list. Subscription management: http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list Archives: http://caml.inria.fr Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs