Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OCaml: When guard in "fun"

Tags:

ocaml

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
like image 955
bmatcuk Avatar asked Mar 09 '26 00:03

bmatcuk


1 Answers

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

like image 116
camlspotter Avatar answered Mar 16 '26 23:03

camlspotter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!