I came across the following design in different places of the Ocaml project. I am reading the code.
match something with true -> foo | false -> bar
At first glance, it works like a regular operator if. At a second glance, it works like a regular ifoperator! At the third glance, I decided to ask in SO. Does this construction have a special meaning or a subtle difference from an expression ifthat matters in special cases?
if
Yes, this is an if statement.
match OCaml-, if, .
match
, if, , .
" - switch, 10 " -
,
, OCAML , , ,
> Let imply v = match v with | True, x -> x | False, _ -> true;; > Let head = function | [] -> 42 | H:: _ -> am; > Let rec sum = function | [] -> 0 | H:: l -> h + sum l;;