Convenient way to write return types of OCaml funs in *.ml files?

Here are two ways:

let foo (x: string) (y: int) : unit = ...
                               ^^^^ here

or

let foo : string -> int -> unit = fun x y -> ...
                           ^^^^ here

Convenient thing about the second way…if you decide you want to remove the type from the function, you can delete this part : string -> int -> unit, and if you’re using ocamlformat, it will automatically change your function to the “normal” form.

2 Likes