What is the simple F # code that generates the .tail IL statement?

I would like to see a .tail IL .tail , but simple recursive functions using tail calls that I wrote are apparently optimized for loops. I actually have a hunch about this, since I'm not quite sure what the loop in Reflector looks like. I definitely don't see any .tail codes. I have a "Generate tail calls" checked in my project properties. I also tried both Debug and Release builds in Reflector.

The code I use is F # Programming by Chris Smith , p. 190:

 let factorial x = // Keep track of both x and an accumulator value (acc) let rec tailRecursiveFactorial x acc = if x <= 1 then acc else tailRecursiveFactorial (x - 1) (acc * x) tailRecursiveFactorial x 1 

Can someone suggest some simple F # code that will actually generate .tail ?

+7
tail-recursion tail-call-optimization f #
source share
1 answer

Mutually recursive functions should:

 let rec even n = if n = 0 then true else odd (n-1) and odd n = if n = 1 then true else even (n-1) 

(did not try it now).

EDIT

see also

How to find out if a function is tail recursive in F #

+6
source share

All Articles