Structured types

Structures

CORBA structures are mapped to caml records. The field names are kept as short as possible but parts of the qualified name of the structure may be prepended if they are needed to disambiguate field names.

this CORBA IDL ...is mapped to:
struct foo {
  string  aaa;
  boolean bbb;
};
type foo = {
  aaa : string ;
  bbb : bool
}
struct foo {
  long   aa;
  string bb;
};

struct bar {
  boolean aa;
  string  cc;
};
type foo = {
  foo_aa : int ;
  foo_bb : string
}

type bar = {
  bar_aa : bool ;
  bar_cc : string
}

Alternatively, a structure can be mapped to a tuple. The field names are lost, but a tuple is sometimes easier to use than a record.

Enumerations

CORBA enumerations are mapped to caml variants with only constant constructors.

Discriminated unions

Discriminated unions are mapped to caml variants with the following rules :

  • Simple cases (one discriminator value, one member value) are mapped to a variant constructor with one argument (the member) ;

  • Multiple cases (several discriminator values, one member value) are mapped to a variant constructor with two arguments : the discriminator and the member ;

  • The default case is mapped to a constructor with two arguments ;

  • Discriminator values without a member value are mapped to a NO_VALUE variant constructor with one argument (the discriminator).

  • Again, parts of the union's name are prepended if needed to disambiguate the constructors.

IDLcaml
union foo switch (short) {
  case 0:
    short aa;
  case 1:
  case 2:
    char  bb:
  default:
    string cc;
};
type foo =
    AA of int
  | BB of int * char
  | CC of int * string
union bar switch (short) {
  case 0:
    char xx;
};
type bar = 
    XX of char
  | BAR_NO_VALUE of int

Note

As an exception, unions of the following kind :

union union_name switch (boolean) {
  case TRUE:
    type field_name;
};

are mapped to

type option