If I'm reading it correctly, the OCaml documentation (here, specifically) says that fun can have "when" guards, such as:
fun a b when a < b -> a + b;;
However, this throws a syntax error on the "when". What gives? Am I reading this wrong?
More Info
The relevant parts from the documentation are copied below in a BNF-like syntax:
expr ::= ...
| fun multiple-matching
| ...
multiple-matching ::= { pattern }+ [when expr] -> expr
You found a bug of the documentation. fun cannot take a guard.
Note: the fix is already pull-requested: https://github.com/ocaml/ocaml-manual/pull/2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With