Tail Recursion Tail recursion is a special form of recursion, in which the final action of a procedure calls itself again. In the above program, the last action is return 1 or return fib_rec(n-1) + fib_rec(n-2) , this is not a tail recursion.
Consider the following hypothetical tail-recursive formulation of a function for computing the Fibonacci numbers let fibhelper ( x : i32 , y : i32 , n : i32 ): i32 = if n == 1 then x else fibhelper ( y , x + y , n -1) let fib ( n : i32 ): i32 = fibhelper (1,1, n ) In programming language theory, lazy evaluation, or call-by-need is an evaluation strategy which delays the evaluation of an expression until its value is needed (non-strict evaluation) and which also avoids repeated evaluations ().
Besides efficiency, tail recursion gives us a way to express iteration. If you already have an iterative The fast Fibonacci function shown above is not tail recursive. Check the pre- and postcondition of the help function! Try translating the tail-recursive Fibonacci into imperative code (say C or Java).To execute F * code one needs to extract it to OCaml or F # and then compile it using the OCaml or F # compiler. More details on executing F* code on the F* wiki. 1.1. Your first F * program: a simple model of access control. Let ' s get started by diving into a simple model of access control on files.