You could label the arguments at the call sites:
let raise_error ~m = failwith m
let test = function
| true -> raise_error ~m:"ok"
| false -> raise_error ~m:"ko"
let test2 = function
| true -> "ok"
| false -> raise_error ~m:"ko"
A better solution is to rewrite raise_error
to not use labelled arguments.
The issue is that raise_error
as written has a type of m:string -> 'a
, so you can pass it any number of non-labelled arguments and the resulting expression will still be a function of type m:string -> 'a
. This is error prone and surprising, so you should avoid using labelled arguments with diverging functions.