Iām a bit surprised by this point. If we check the the documentation on the C interfacing, it requires an explicit anotation [@@unboxed] otherwise it cost an indirection.
Edit : got it, this is bit later in the documentation:
As an optimization, unboxable concrete data types are represented specially; a concrete data type is unboxable if it has exactly one constructor and this constructor has exactly one argument. Unboxable concrete data types are represented in the same ways as unboxable record types
If you want to be told when this sort of things happen (when a ālast in scopeā choice makes reordering types more fragile), you may want to enable warning 41 (ambiguous-name) by default:
$ ocamlc -w +ambiguous-name test.ml
File "test.ml", line 5, characters 15-16:
5 | let f' b = b.x in f' b
^
Warning 41 [ambiguous-name]: x belongs to several types: bt at
The first one was selected. Please disambiguate if this is wrong.
I feel this inference question is quite common and should be added to an FAQ, or at least to the ācommon errorsā page: Common Error Messages Ā· OCaml Tutorials
No, thatās actually an example of inline records, not a standalone record type. You could have multiple constructors using inline records with multiple fields each and their representation would still be a single block for each.