zzz6519003 / blog

My blog about coding
4 stars 1 forks source link

pattern match #124

Open zzz6519003 opened 4 years ago

zzz6519003 commented 4 years ago

/* Based on https://rosettacode.org/wiki/FizzBuzz#OCaml */
let fizzbuzz = (i) =>
  switch (i mod 3, i mod 5) {

  | (0, 0) => "FizzBuzz"
  | (0, _) => "Fizz"
  | (_, 0) => "Buzz"
  | _ => string_of_int(i)
  };

for (i in 1 to 20) {
  Js.log(fizzbuzz(i))
};
zzz6519003 commented 4 years ago

but if you change the order to

  | (_, 0) => "Buzz"
  | (0, 0) => "FizzBuzz"
  | (0, _) => "Fizz"
  | _ => string_of_int(i)
zzz6519003 commented 4 years ago

you get: Warning number 11 OCaml preview 4:5-9

this match case is unused.

zzz6519003 commented 4 years ago

how awesome