- Int or Char: Stored directly as a value, shifted left by 1 bit, with the least significant bit set to 1.
- Unit,
[]
, false: Stored as OCaml int 0
.
- True: Stored as OCaml int
1
.
- Variants without parameters (e.g.,
Foo | Bar
): Stored as ascending OCaml ints, starting from 0
.
- Variants with parameters (e.g.,
Foo | Bar of int
):
- With parameters: Boxed.
- Without parameters: Unboxed.
- Polymorphic variants:
- With parameters: Boxed with an extra header word to store the value.
- Without parameters: Unboxed.
- Floating-point numbers: Stored as a block with a single field containing the double-precision float.
- Strings: Word-aligned byte arrays with an explicit length.
- Lists:
[1; 2; 3]
lists are stored as 1::2::3::[]
where []
is an int, and h::t
is a block with tag 0
and two parameters.
- Tuples, records, and arrays: Stored as a C array of values.
- Arrays: Can be variable size.
- Tuples and records: Fixed-size.
- Records or arrays that are all float: Use a special tag for unboxed arrays of floats or records that only have float fields.