How to identify OCaml extensible variant type value in C?

Viewed 76

I have an OCaml library and want to use it in C. This library has an error management system based on extensible variants. Chapter 20 Interfacing C with OCaml contains a description of how to identify variant type value in C (it dependent on constructors order).

The following example illustrates the assignment of integers and block tags to constructors:

type t =
  | A             (* First constant constructor -> integer "Val_int(0)" *)
  | B of string   (* First non-constant constructor -> block with tag 0 *)
  | C             (* Second constant constructor -> integer "Val_int(1)" *)
  | D of bool     (* Second non-constant constructor -> block with tag 1 *)
  | E of t * t    (* Third non-constant constructor -> block with tag 2 *)

How to identify extensible variant type value in C?

0 Answers
Related