Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an obvious way to confirm if a function is tail recursive?

Is there any way to tell if a function in F# is tail-recursive?

I've tried to explain it, but some people seem to struggle and ask if there's a way to confirm what they've done is tail recursive. Is there anything easy you can do (other than trying to make it overflow the stack) to confirm tail responsiveness (or not) (preferably in the IDE)?

(I tried Reflector, but it just crashes on me when I open F# projects!)

like image 622
Danny Tuppeny Avatar asked Oct 29 '13 13:10

Danny Tuppeny


1 Answers

From here (with several examples in the article):

How can I verify that tail calls are being used?

The easiest way is to ensure that tail calls are being used is to understand and apply the rules from the previous section. While the F# compiler itself doesn’t currently provide any way to verify that tail calls have been used at a particular call site, you can be sure by looking at the compiled version of the code using the MSIL Dissasembler (ildasm.exe). We’ll see several examples below.

like image 198
David Brabant Avatar answered Oct 24 '22 23:10

David Brabant