As a learning Exercise with the FizzBuzz code in F#.
Reference with code here is working fine and looks good
In above code I want to learn/use match instead of if conditions as below so have wrote below function which works for any given int value.
let fizzbuzz num =
match num with
| x when (x % 3 = 0 && x % 5 = 0) -> printfn "%s" "FizzBuzz"
| x when (x % 3 = 0) -> printfn "%s" "Fizz"
| x when (x % 5 = 0) -> printfn "%s" "Buzz"
| _ -> printfn "%s" (num.ToString())
;;
output:
fizzbuzz 15;;
FizzBuzz
val it : unit = ()
However In my above code needed to use list as input and make function as recursive. how can I do it? I understand working of list i.e using h::t
and pass t
as recurisve to fizzbuzz
. I am struggling with syntax i guess.
Appericate you guidance on how to use list (pattern matching and accumulator argument) in above code?
Is there any blog/reference on how to use F# Interactive window with less keystokes as i found myself typing complete code again for any syntax error