Taking the example FizzBuzz
implementation, I wanted to see if the pattern matching could be used to return more than just the inferred type of string
. Aside from design decisions, is it possible to implement this? Keep in mind that the actual working example utilizes string_of_int(i)
to satisfy the expected type.
let fizzbuzz = (i) =>
switch (i mod 3, i mod 5) {
| (0, 0) => "FizzBuzz"
| (0, _) => "Fizz"
| (_, 0) => "Buzz"
| _ => i /* Can I intentionally return an int here */
};
for (i in 1 to 100) {
Js.log(fizzbuzz(i))
};