It’s even clearer to define it this way: we can almost imagine “copy/pasting” the function’s definition in place.
let ( or ) opt default = Option.value ~default opt
let my_func =
...
let curr = Hashtbl.find_opt tbl key or [] in
(* vs *)
let curr = Hashtbl.find_opt tbl key |> Option.value ~default:[] in
The only downside I can see with this approach is that it becomes a little less clear to a reader where the function ends, i.e. or looks like a third parameter to Hashtbl.find_opt.
It pops out with the site’s current syntax highlighting but not in vscode at least.
I’ll file a feature request. If we can define or as an operator, then it sounds to me like we should be allowed to use or as an identifier.
As a bit of history, the OCaml team removed ( or ) as an operator from the standard library and deprecated that keyword a long time ago. It’s probably more of an accident than anything else that it’s still around. I would suggest using another operator for this kind of ‘boolean-like’ logic, maybe ( |? ).