Fibonacci numbers in F#
Example for versions
fsharp 2.0.0
This example uses straightforward recursive definition of Fibonacci numbers, expressed in procedural paradigm.
let rec fibonacci n =
match n with
| 1 | 2 -> 1
| _ -> fibonacci (n-1) + fibonacci (n-2)
let rec printFib n =
match n with
| 1 -> printf "%d, " (fibonacci (n))
| _ -> printFib (n-1)
printf "%d, " (fibonacci (n))
printFib(16)
printfn "..."
Comments
]]>blog comments powered by Disqus
]]>