Evaluation of defaults of optional parameters is pushed under function binders in a way that is not always sound:
OCaml version 4.12.0
# let s = 42;;
val s : int = 42
# let f ?(s="hello") = function x when (print_string s; true) -> x;;
Warning 8 [partial-match]: this pattern-matching is not exhaustive.
All clauses in this pattern-matching are guarded.
val f : ?s:string -> 'a -> 'a = <fun>
# f ();;
Segmentation fault
f gets translated to something resembling:
let f opt = function
| x when (print_string s; true) ->
let s = match opt with Some s -> s | None -> "hello" in
x
where the s in the guard is the wrong one.