Has anything changed recently for handling optional arguments?

I tried to compile old code with latest OCaml, Dune, etc
I have write function looking like:

let write ~path ?(pos=0) ~data =
....

This code emits warning with OCaml 4.12.0

Error (warning 16 [unerasable-optional-argument]): this optional argument cannot be erased.

Even if I put it as the last one, the warning persists. Why this new warning? I thought it should not be the last. What is the correct position in this case?

1 Like

If you only have labeled arguments, the optional argument can not be erased in a labeled application, independently of its position. The fact that such argument is only optional when using the unlabelled full application short-hand,

write path data

was deemed worthy of a warning.

4 Likes