Default of Option.value?

I am puzzled by this:

# Option.value ~default:(failwith "aze") (Some 3);;
Exception: Failure "aze".

I would expect, both from the documentation OCaml library : Option and from the stdlib implementation

let value o ~default = match o with Some v -> v | None -> default

to get

- : int = 3

Can someone explain why this is not so ?

1 Like

Are you a Haskeller :–) ?

OCaml’s evaluation strategy is strict, the arguments are evaluated before the function is called, so your expression (failwith "aze") is evaluated before Option.value and raises the exception.