This might sound like a School assignment but it is not!
I have made a recursive function returning a value from the Fibonacci Sequence.
let rec FoneFive n =
match n with
| 1 | 2 -> 1
| n -> FoneFive(n-1) + FoneFive(n-2)
printfn "%A" (FoneFive 6)
What is going on in this recursive function? FoneFive 6
gives 8 as it should. But why?
The way I see it: It starts with n=6 and concludes that 6 is not 1 or 2. So it calls FoneFive(n-1) + FoneFive(n-2)
. (This is probably where I get it wrong. But the way I see it is that this return nothing unless n is 1 or 2. So from my point of view it will narrow both down n = 1 or 2 and there by say 1 + 1 which of course is 2.)
Can someone tell me how it returns 8 ?