Created
November 9, 2012 13:41
-
-
Save 1tgr/4045710 to your computer and use it in GitHub Desktop.
F# tail recursion optimization
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let rec fact acc = | |
| function | |
| | 1 -> acc | |
| | n -> fact (acc * n) (n - 1) | |
| assert fact 1 6 == 720 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| .method public static | |
| default int32 fact (int32 acc, int32 _arg1) cil managed | |
| { | |
| .custom instance void class [FSharp.Core]Microsoft.FSharp.Core.CompilationArgumentCountsAttribute::'.ctor'(int32[]) = ( | |
| 01 00 02 00 00 00 01 00 00 00 01 00 00 00 00 00 ) // ................ | |
| // Method begins at RVA 0x2050 | |
| // Code size 26 (0x1a) | |
| .maxstack 5 | |
| IL_0000: ldarg.1 | |
| IL_0001: ldc.i4.1 | |
| IL_0002: sub | |
| IL_0003: switch ( | |
| IL_0018) | |
| IL_000c: ldarg.0 | |
| IL_000d: ldarg.1 | |
| IL_000e: mul | |
| IL_000f: ldarg.1 | |
| IL_0010: ldc.i4.1 | |
| IL_0011: sub | |
| IL_0012: starg.s 1 | |
| IL_0014: starg.s 0 | |
| IL_0016: br.s IL_0000 | |
| IL_0018: ldarg.0 | |
| IL_0019: ret | |
| } // end of method Tim::fact |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment