Version française
Home     About     Download     Resources     Contact us    
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: -- (:)
From: Jean Yang <jeanyang@c...>
Subject: OCaml/C variant representation
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?

Thanks,
Jean

-- 
Jean Yang
http://people.csail.mit.edu/jeanyang
Save us!  Think before you print.