4 ms·
In OCaml : let expression a b c = match (a, b, c) with | (true, true, true) => 2, | (true, true, _) => 1, | (false, _, _) =
by roblabla 10y ago
In OCaml :
let expression a b c = match (a, b, c) with
| (true, true, true) => 2,
| (true, true, _) => 1,
| (false, _, _) => 0
I like how pattern matching allows you to create something very close to a truth table. It allows you to visually see what's going on.
EDIT: Just realized that the two code examples in the parent's link don't even do the same... Look at the truth table, and look at the case of 1 1 0. The first code would indeed return 0, but not the second one. Derp.