You can use when to create patterns along with boolean conditions:
let check n = function | x when x = n -> true | _ -> false
However, this is not very important: this is just great syntax for using if .
OCaml does not support any βdynamicβ template, which allows you to map the value of a variable - templates, all static. There is a bondi research language that supports dynamic patterns like this. This is very similar to OCaml, so if you are interested in such a feature, you should play with it.
source share