Pattern matching a variable in OCaml?
问题 If I do let check n = function | n -> true | _ -> false then I get Warning 11: this match case is unused. I understand why , since the n in | n -> true is actually not the argument of check . It is basically a variable created by the pattern matching. My question is , in this case, do we have any way to still using pattern matching (instead of if else) to force this check? I.e., I want to pattern match with the argument n . 回答1: You can use when to have patterns along with boolean conditions: