HomeUpSign my Guestbook!RSS • Published: 2026-03-14 • Powered by IPFS

OCaml has curried keywords


I spoke about keywords improving readability in an older post.

And actually found something that does it close to what I described.

OCaml calls it “Labelled Arguments”:

# let add ~x ~y = x + y;;
val add : x:int -> y:int -> int = <fun>

# add ~x:2 ~y:4;;
- : int = 6

# add ~y:2 ~x:5;;
- : int = 7

# add ~y:4;;
- : x:int -> int = <fun>

Sadly you can’t do something like add ~x to remove the label from the argument, it’s a labelled argument, it’s a different type and that’s that unless you wrap it in a lambda.

They also have an interesting approach to optional arguments, where you can just skip over them when applying a later label? This of course means you need a sentinel value if there are no non-optional arguments and also that optional arguments come first rather than last.