3 ms·
Well since .tail is only a hint, F# must do it in some cases. Try writing a simple recursive function in tail call style and look at the IL produced by fsc.
by MichaelGG 11y ago
Well since .tail is only a hint, F# must do it in some cases. Try writing a simple recursive function in tail call style and look at the IL produced by fsc.
- jdmichal 11y agoI was basing my statement on this line from the MSDN blog I linked: > This is such an important concept that the JIT has a special path just for turning functions that call themselves in a tail recursive manner into loops. However, it looks like (in at least some cases) that fsc unrolls the recursion prior to the JIT: let rec fact n acc = match n with | 0 -> acc | _ -> fact (n-1) (acc*n) .method assembly static int32 fact@1(int32 n, int32 acc) cil managed { // Code size 24 (0x18) .maxstack 5 IL_0000: ldarg.0 IL_0001: switch ( IL_0016) IL_000a: ldarg.0 IL_000b: ldc.i4.1 IL_000c: sub IL_000d: ldarg.1 IL_000e: ldarg.0 IL_000f: mul IL_0010: starg.s acc IL_0012: starg.s n IL_0014: br.s IL_0000 IL_0016: ldarg.1 IL_0017: ret } // end of method TailTest::fact@1