Given the following function
let get_or ~default =
function | Some a -> a
| None -> default
If this function is called with the argument labeled, it works as expected:
let works = get_or ~default:4 (Some 2)
But if the label is omitted it somehow fails:
let fails = get_or 4 (Some 2)
It gets weirder, however, the error message given here by the compiler is:
This expression has type int but an expression was expected of type ('a -> 'b) option
Not only has the compiler incorrectly inferred it to be an option, but for some reason it also pulls a function type out of the proverbial magician's hat! So naturally I wonder: where on earth does that come from? And somewhat less immediately important to my curiosity, why doesn't omitting the label work in this specific case?
See this reason playground for an interactive example.
Credit for this puzzle goes to @nachotoday on the Reason Discord.