{"id":582,"date":"2024-01-09T02:05:49","date_gmt":"2024-01-09T10:05:49","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/?p=582"},"modified":"2024-01-28T19:11:23","modified_gmt":"2024-01-29T03:11:23","slug":"f-%e4%b8%ad%e6%9b%b4%e5%ae%89%e5%85%a8%e7%9a%84%e9%80%92%e5%bd%92","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/f-%e4%b8%ad%e6%9b%b4%e5%ae%89%e5%85%a8%e7%9a%84%e9%80%92%e5%bd%92\/","title":{"rendered":"F# \u4e2d\u66f4\u5b89\u5168\u7684\u9012\u5f52"},"content":{"rendered":"<p><em>\u672c\u7bc7\u7ffb\u8bd1\u4e8eDavid Schaefer\u7684<a href=\"https:\/\/devblogs.microsoft.com\/dotnet\/safer-recursion-in-fsharp\/\">Safer recursion in F#<span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"auto\"><span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW257415048 BCX8\">\u3002<\/span><\/span><\/a><\/em><\/p>\n<blockquote><p><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">\u8fd9\u662f<\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">David Schaefer<\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">\u7684\u5ba2\u5ea7\u535a\u5ba2\u6587\u7ae0\u3002<\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">David <\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">\u662f\u4e00\u540d\u4e13\u6ce8\u4e8e\u51fd\u6570\u5f0f\u7f16\u7a0b<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u7684<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u81ea\u7531\u8f6f\u4ef6\u5f00\u53d1\u4eba\u5458<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u3002\u4ed6\u662f<\/span><\/span><a class=\"Hyperlink SCXW257415048 BCX8\" href=\"https:\/\/opensource.gresearch.com\/\" target=\"_blank\" rel=\"noreferrer noopener\"><span class=\"TextRun Underlined SCXW257415048 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW257415048 BCX8\" data-ccp-charstyle=\"Hyperlink\">G-Research<\/span><\/span><span class=\"TextRun Underlined SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"none\"><span class=\"NormalTextRun SCXW257415048 BCX8\" data-ccp-charstyle=\"Hyperlink\">\u5f00\u6e90\u56e2\u961f<\/span><\/span><\/a><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">\u7684<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u4e00<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u5458\u3002\u4ed6\u81f4\u529b\u4e8e\u6539\u8fdb<\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\"> F# <\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">\u5f00\u53d1\u8005\u5de5\u5177\u7684<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u751f\u6001\u7cfb\u7edf<\/span><span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW257415048 BCX8\">\u3002<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u6b64\u5916\uff0c\u4ed6\u8fd8\u5e2e\u52a9\u7ef4\u62a4\u5404\u79cd<\/span><span class=\"NormalTextRun SCXW257415048 BCX8\">\u5f00\u6e90\u7684<\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"EN-US\" xml:lang=\"EN-US\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\"> F# <\/span><\/span><span class=\"TextRun Highlight SCXW257415048 BCX8\" lang=\"ZH-CN\" xml:lang=\"ZH-CN\" data-contrast=\"auto\"><span class=\"NormalTextRun SCXW257415048 BCX8\">\u9879\u76ee<span class=\"NormalTextRun ContextualSpellingAndGrammarErrorV2Themed SCXW257415048 BCX8\">\u3002<\/span><\/span><\/span><\/p><\/blockquote>\n<p><span data-contrast=\"auto\">\u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d<\/span><span data-contrast=\"auto\">\uff0c<\/span><span data-contrast=\"auto\">\u7528\u9012\u5f52\u7684\u65b9\u5f0f\u53bb\u5b9a\u4e49\u7b97\u6cd5\u662f\u5f88\u5e38\u89c1\u7684\u573a\u666f<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-contrast=\"auto\">\u8fd9\u975e\u5e38\u7b26\u5408\u6211\u4eec\u60f3\u8981\u907f\u514d\u7a81\u53d8\u7684\u5fc3\u6001\uff0c\u800c\u4e14\u8fd9\u901a\u5e38\u4e0d\u4f1a\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002\u7f16\u8bd1\u5668\u5728\u4f18\u5316\u9636\u6bb5\u4f1a\u5c1d\u8bd5\u5c06\u9012\u5f52\u5b9a\u4e49\u91cd\u5199\u4e3a\u66f4\u9ad8\u6548\u7684\u5faa\u73af\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u7136\u800c\uff0c\u7f16\u8bd1\u5668\u5e76\u4e0d\u603b\u662f\u80fd\u591f\u5c06\u9012\u5f52\u8f6c\u6362\u4e3a\u5faa\u73af\u3002\u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u5c31\u6709\u4e00\u5b9a\u7684\u5371\u9669\u4e86<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">\u5806\u6808\u5e27\u4e0e\u751f\u4ea7\u73af\u5883<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5f53\u6211\u4eec\u5728\u51fd\u6570<\/span><span data-contrast=\"auto\"> f <\/span><span data-contrast=\"auto\">\u5185\u90e8\u8c03\u7528\u51fd\u6570<\/span><span data-contrast=\"auto\"> g <\/span><span data-contrast=\"auto\">\u65f6\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u901a\u5e38\u4f1a\u5728\u8fdb\u7a0b\u7684\u8c03\u7528\u5806\u6808\u4e0a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5806\u6808\u5e27\u3002\u51fd\u6570<\/span><span data-contrast=\"auto\">g<\/span><span data-contrast=\"auto\">\u5b8c\u6210\u540e\uff0c\u7a0b\u5e8f\u6b64\u65f6\u5c31\u4e0d\u518d\u9700\u8981\u5b83\u7684\u5806\u6808\u5e27\u4e86<\/span><span data-contrast=\"auto\">\uff0c<\/span><span data-contrast=\"auto\">\u4ece\u800c\u53ef\u4ee5\u91cd\u7528\u5b83\u7684\u7a7a\u95f4<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u73b0\u5728\uff0c\u7406\u89e3\u5806\u6808\u5e27\u7684\u521b\u5efa\u5bf9\u4e8e\u9012\u5f52\u51fd\u6570\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u9012\u5f52\u8c03\u7528\uff0c\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5806\u6808\u5e27\u3002\u5728\u5f00\u53d1\u671f\u95f4\uff0c\u5f53\u89c4\u6a21\u8f83\u5c0f\u65f6\uff0c\u8fd9\u901a\u5e38\u4e0d\u4f1a\u5f15\u8d77\u95ee\u9898\u3002\u4f46\u5728\u540e\u671f\u7684\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u968f\u7740\u89c4\u6a21\u7684\u6269\u5927\uff0c\u7a0b\u5e8f\u4f1a\u56e0\u5806\u6808\u6ea2\u51fa\u800c\u7a81\u7136\u5d29\u6e83\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u7531\u4e8e\u9012\u5f52\u8c03\u7528\u521b\u5efa\u4e86\u592a\u591a\u5806\u6808\u5e27\uff0c\u5806\u6808\u7684\u6240\u6709\u7a7a\u95f4\u90fd\u88ab\u7528\u5b8c\u4e86<\/span><span data-contrast=\"auto\">\uff0c<\/span><span data-contrast=\"auto\">\u6240\u4ee5<\/span><span data-contrast=\"auto\">runtime<\/span><span data-contrast=\"auto\">\u51b3\u5b9a\u505c\u6b62\u5b83\u3002<\/span> <span data-contrast=\"auto\">\u4e3a\u4e86\u6f14\u793a\u8fd9\u4e00\u573a\u666f\uff0c\u8bf7\u770b\u4e00\u4e0b\u8fd9\u4e2a\u9012\u5f52\u51fd\u6570<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">let rec countDown1 n =\r\n    if n = 0\r\n    then 0\r\n    else\r\n        countDown1 (n - 1) + 1<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u751f\u6210\u7684<\/span><span data-contrast=\"auto\"> IL <\/span><span data-contrast=\"auto\">\u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">.method public static \r\n    int32 countDown1 (\r\n        int32 n\r\n    ) cil managed \r\n{\r\n    \/\/ Method begins at RVA 0x2050\r\n    \/\/ Header size: 1\r\n    \/\/ Code size: 17 (0x11)\r\n    .maxstack 8\r\n\r\n    IL_0000: nop\r\n    IL_0001: ldarg.0\r\n    IL_0002: brtrue.s IL_0006\r\n\r\n    IL_0004: ldc.i4.0\r\n    IL_0005: ret\r\n\r\n    IL_0006: ldarg.0\r\n    IL_0007: ldc.i4.1\r\n    IL_0008: sub\r\n    IL_0009: call int32 Program::countDown1(int32)\r\n    IL_000e: ldc.i4.1\r\n    IL_000f: add\r\n    IL_0010: ret\r\n} \/\/ end of method Program::countDown1<\/code><\/pre>\n<p><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><span data-contrast=\"auto\">\u60a8\u53ef\u4ee5\u5728<\/span><span data-contrast=\"auto\"> IL_0009 <\/span><span data-contrast=\"auto\">\u5904\u770b\u5230\u9012\u5f52\u8c03\u7528\u3002<\/span> <span data-contrast=\"auto\">\u5f53\u4f7f\u7528<\/span><span data-contrast=\"auto\"> n = 1_000 <\/span><span data-contrast=\"auto\">\u6765\u8c03\u7528<\/span><span data-contrast=\"auto\"> coundDown1<\/span><span data-contrast=\"auto\">\u65f6\uff08\u5c31\u50cf\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u968f\u610f\u5199\u7684\u6570\u503c<\/span><span data-contrast=\"auto\">\uff09<\/span><span data-contrast=\"auto\">\u4ee3\u7801\u4f1a\u6b63\u786e\u7684\u7ed3\u675f\u8c03\u7528\uff0c\u4f46\u4f7f\u7528<\/span><span data-contrast=\"auto\"> n = 1_000_000 <\/span><span data-contrast=\"auto\">\u6765\u8c03\u7528\u5b83\u65f6\uff0c\u5b83\u4f1a\u56e0\u5806\u6808\u6ea2\u51fa\u800c\u5d29\u6e83<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5c06\u4e0a\u9762\u7684\u5185\u5bb9\u4e0e\u4ee5\u4e0b\u5185\u5bb9\u8fdb\u884c\u6bd4\u8f83\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">let rec countDown2 n =\r\n    if n = 0\r\n    then 0\r\n    else\r\n        countDown2 (n - 1)<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u7ed3\u679c\u662f\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">.method public static \r\n    int32 countDown2 (\r\n        int32 n\r\n    ) cil managed \r\n{\r\n    \/\/ Method begins at RVA 0x2064\r\n    \/\/ Header size: 1\r\n    \/\/ Code size: 13 (0xd)\r\n    .maxstack 8\r\n\r\n    \/\/ loop start\r\n        IL_0000: nop\r\n        IL_0001: ldarg.0\r\n        IL_0002: brtrue.s IL_0006\r\n\r\n        IL_0004: ldc.i4.0\r\n        IL_0005: ret\r\n\r\n        IL_0006: ldarg.0\r\n        IL_0007: ldc.i4.1\r\n        IL_0008: sub\r\n        IL_0009: starg.s n\r\n        IL_000b: br.s IL_0000\r\n    \/\/ end loop\r\n} \/\/ end of method Program::countDown2<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u4e24\u6bb5\u4ee3\u7801\u7684\u4e0d\u540c\u4e4b\u5904\u5728\u4e8e\uff0c\u5728<\/span><span data-contrast=\"auto\"> countDown1 <\/span><span data-contrast=\"auto\">\u4e2d\uff0c\u9012\u5f52\u8c03\u7528\u7684\u8fd4\u56de\u503c\u8fd8\u9700\u8981\u901a\u8fc7\u52a0<\/span><span data-contrast=\"auto\"> 1 <\/span><span data-contrast=\"auto\">\u6765\u8f93\u51fa\u51fd\u6570\u7684\u6700\u7ec8\u503c\u3002<\/span> <span data-contrast=\"auto\">\u76f8\u53cd\uff0c\u5728<\/span><span data-contrast=\"auto\"> countDown2 <\/span><span data-contrast=\"auto\">\u4e2d\uff0c\u9012\u5f52\u8c03\u7528\u7684\u8fd4\u56de\u503c\u4e5f\u662f\u51fd\u6570\u672c\u8eab\u7684\u503c\u3002<\/span> <span data-contrast=\"auto\">\u8fd9\u610f\u5473\u7740\uff0c\u9012\u5f52\u8c03\u7528\u662f\u51fd\u6570\u5b9a\u4e49\u4e2d\u7684\u6700\u540e\u4e00\u6761\u6307\u4ee4<\/span><span data-contrast=\"auto\">\u2014\u2014<\/span><span data-contrast=\"auto\">\u8fd9\u79cd\u65b9\u5f0f\u79f0\u4e3a<\/span><a href=\"https:\/\/en.wikipedia.org\/wiki\/Tail_call\"><span data-contrast=\"none\">\u5c3e\u9012\u5f52<\/span><\/a><span data-contrast=\"auto\">\u3002 <\/span><span data-contrast=\"auto\">\u8fd9\u79cd\u98ce\u683c\u5141\u8bb8\u7f16\u8bd1\u5668\u5c06\u51fd\u6570\u8f6c\u6362\u4e3a\u5faa\u73af\uff0c\u4ece\u800c\u65e0\u9700\u521b\u5efa\u65b0\u7684\u5806\u6808\u5e27<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u9664\u4e86\u7f16\u8bd1\u5668\u6709\u673a\u4f1a\u5c06\u9012\u5f52\u51fd\u6570\u91cd\u5199\u4e3a\u5faa\u73af\u4e4b\u5916\uff0c\u4f7f\u7528\u5c3e\u9012\u5f52\u8fd8\u5c06\u6253\u5f00\u53e6\u4e00\u4e2a\u9003\u751f\u95e8\uff1a<\/span><span data-contrast=\"auto\">IL <\/span><span data-contrast=\"auto\">\u524d\u7f00<\/span><span data-contrast=\"auto\"> tail\u3002 <\/span><span data-contrast=\"auto\">\u5728<\/span><a href=\"https:\/\/ecma-international.org\/publications-and-standards\/standards\/ecma-335\/\"><span data-contrast=\"none\">ECMA-335<\/span><\/a><span data-contrast=\"auto\">\u4e2d\uff0c\u662f\u8fd9\u6837\u89e3\u91ca\u7684<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">\u5b83\u8868\u793a\u4e0d\u518d\u9700\u8981\u5f53\u524d\u65b9\u6cd5\u7684\u5806\u6808\u5e27\uff0c\u56e0\u6b64\u53ef\u4ee5\u5728\u6267\u884c\u8c03\u7528\u6307\u4ee4\u4e4b\u524d\u5c06\u5176\u5220\u9664\u3002\u7531\u4e8e\u8c03\u7528\u8fd4\u56de\u7684\u503c\u5c06\u662f\u6b64\u65b9\u6cd5\u8fd4\u56de\u7684\u503c\uff0c\u56e0\u6b64\u53ef\u4ee5\u5c06\u8c03\u7528\u8f6c\u6362\u4e3a\u8de8\u65b9\u6cd5\u8df3\u8f6c\u3002<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u4e3a\u4e86\u6f14\u793a\u5b83\uff0c\u6211\u4eec\u4f7f\u7528<\/span> <a href=\"https:\/\/github.com\/fsharp\/fslang-design\/blob\/main\/FSharp-8.0\/FS-1011-warn-on-recursive-without-tail-call.md\"><span data-contrast=\"none\">RFC-1011<\/span><\/a> <span data-contrast=\"auto\">\u4e2d\u7684\u793a\u4f8b\uff0c\u7a0d\u540e\u4f1a\u8be6\u7ec6\u4ecb\u7ecd\u3002<\/span> <span data-contrast=\"auto\">\u8003\u8651\u76f8\u4e92\u9012\u5f52\u7684<\/span><span data-contrast=\"auto\"> F# <\/span><span data-contrast=\"auto\">\u51fd\u6570<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">let foo x =\r\n    printfn \"Foo: %x\" x\r\n\r\n[&lt;TailCall&gt;]\r\nlet rec bar x =\r\n    match x with\r\n    | 0 -&gt;\r\n        foo x           \/\/ OK: non-tail-recursive call to a function which doesn't share the current stack frame (i.e., 'bar' or 'baz').\r\n        printfn \"Zero\"\r\n\r\n    | 1 -&gt;\r\n        bar (x - 1)     \/\/ Warning: this call is not tail-recursive\r\n        printfn \"Uno\"\r\n        baz x           \/\/ OK: tail-recursive call.\r\n\r\n    | x -&gt;\r\n        printfn \"0x%08x\" x\r\n        bar (x - 1)     \/\/ OK: tail-recursive call.\r\n\r\nand [&lt;TailCall&gt;] baz x =\r\n    printfn \"Baz!\"\r\n    bar (x - 1)         \/\/ OK: tail-recursive call.<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u8fd9\u91cc\u6211\u4eec\u5f97\u5230<\/span><span data-contrast=\"auto\"> bar <\/span><span data-contrast=\"auto\">\u4e2d\u6848\u4f8b<\/span><span data-contrast=\"auto\"> 1 <\/span><span data-contrast=\"auto\">\u7684\u4ee5\u4e0b<\/span><span data-contrast=\"auto\"> IL <\/span><span data-contrast=\"auto\">\u4ee3\u7801<\/span><span data-contrast=\"auto\">\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">    ...\r\n    IL_0030: ldarg.0\r\n    IL_0031: ldc.i4.1\r\n    IL_0032: sub\r\n    IL_0033: call void Program::bar(int32)\r\n    IL_0038: nop\r\n    IL_0039: ldstr \"Uno\"\r\n    IL_003e: newobj instance void class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`5&lt;class [FSharp.Core]Microsoft.FSharp.Core.Unit, class [System.Runtime]System.IO.TextWriter, class [FSharp.Core]Microsoft.FSharp.Core.Unit, class [FSharp.Core]Microsoft.FSharp.Core.Unit, class [FSharp.Core]Microsoft.FSharp.Core.Unit&gt;::.ctor(string)\r\n    IL_0043: stloc.0\r\n    IL_0044: call class [netstandard]System.IO.TextWriter [netstandard]System.Console::get_Out()\r\n    IL_0049: ldloc.0\r\n    IL_004a: call !!0 [FSharp.Core]Microsoft.FSharp.Core.PrintfModule::PrintFormatLineToTextWriter&lt;class [FSharp.Core]Microsoft.FSharp.Core.Unit&gt;(class [System.Runtime]System.IO.TextWriter, class [FSharp.Core]Microsoft.FSharp.Core.PrintfFormat`4&lt;!!0, class [System.Runtime]System.IO.TextWriter, class [FSharp.Core]Microsoft.FSharp.Core.Unit, class [FSharp.Core]Microsoft.FSharp.Core.Unit&gt;)\r\n    IL_004f: pop\r\n    IL_0050: ldarg.0\r\n    IL_0051: tail.\r\n    IL_0053: call void Program::baz(int32)\r\n    IL_0058: ret\r\n    ...<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u56e0\u4e3a\u5bf9<\/span><span data-contrast=\"auto\"> baz <\/span><span data-contrast=\"auto\">\u7684\u8c03\u7528\u4ee5\u5c3e\u9012\u5f52\u65b9\u5f0f\u8fdb\u884c\uff0c\u6240\u4ee5\u7f16\u8bd1\u5668\u53ef\u4ee5\u5728<\/span><span data-contrast=\"auto\"> IL_0051 <\/span><span data-contrast=\"auto\">\u4e2d\u4f7f\u7528<\/span><span data-contrast=\"auto\">tail<\/span><span data-contrast=\"auto\">\u524d\u7f00<\/span><span data-contrast=\"auto\">\u3002 <\/span><span data-contrast=\"auto\">\u5c06\u6b64\u4e0e<\/span><span data-contrast=\"auto\"> IL_0033 <\/span><span data-contrast=\"auto\">\u4e2d\u5bf9<\/span><span data-contrast=\"auto\"> bar <\/span><span data-contrast=\"auto\">\u7684\u8c03\u7528\u8fdb\u884c\u6bd4\u8f83<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">\u8ba9\u7f16\u8bd1\u5668\u7406\u89e3\u4f60\u7684\u610f\u56fe<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6240\u4ee5\uff0c\u4e3a\u4e86\u7ee7\u7eed\u4f18\u96c5\u7684\u4f7f\u7528\u9012\u5f52\u51fd\u6570\uff0c\u6211\u4eec\u53ea\u8981\u7528\u5c3e\u9012\u5f52\u7684\u65b9\u5f0f\u53bb\u5b9a\u4e49\u5b83\u4eec\uff0c\u5bf9\u5417\uff1f<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u8bf4\u8d77\u6765\u5bb9\u6613\u505a\u8d77\u6765\u96be\u3002<\/span> <span data-contrast=\"auto\">\u968f\u7740\u51fd\u6570\u7684\u590d\u6742\u6027\u589e\u52a0\u4ee5\u53ca\u4e0d\u540c\u7684\u7a0b\u5e8f\u5458\u5bf9\u4ee3\u7801\u7684\u5904\u7406\uff0c\u786e\u4fdd\u4ee5\u5c3e\u9012\u5f52\u65b9\u5f0f\u5b9a\u4e49\u51fd\u6570\u53ef\u80fd\u662f\u4e00\u9879\u6311\u6218\u3002<\/span> <span data-contrast=\"auto\">\u56e0\u6b64\uff0c\u7f16\u8bd1\u5668\u6700\u597d\u80fd\u6839\u636e\u5f00\u53d1\u4eba\u5458\u7684\u610f\u56fe\uff0c\u5bf9\u5e94\u8be5\u662f\u5c3e\u9012\u5f52\u7684\uff0c\u4f46\u5374\u4e0d\u662f\u5c3e\u9012\u5f52\u7684\u51fd\u6570\u53d1\u51fa\u8b66\u544a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u8fd9\u6b63\u662f<\/span> <a href=\"https:\/\/github.com\/fsharp\/fslang-design\/blob\/main\/FSharp-8.0\/FS-1011-warn-on-recursive-without-tail-call.md\"><span data-contrast=\"none\">RFC-1011<\/span><\/a> <span data-contrast=\"auto\">\u6240\u53d1\u751f\u7684\u60c5\u51b5\u3002<\/span><span data-contrast=\"auto\"> F# <\/span><span data-contrast=\"auto\">\u7f16\u8bd1\u5668\u4e2d\u5b9e\u73b0\u4e86\u65b0\u5c5e\u6027<\/span><span data-contrast=\"auto\"> [&lt;TailCall&gt;]\u3002 <\/span><span data-contrast=\"auto\">\u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u660e\u786e\u81ea\u5df1\u7684\u610f\u56fe<\/span><span data-contrast=\"auto\">\u2014\u2014<\/span><span data-contrast=\"auto\">\u8fd9\u4e2a\u51fd\u6570\u5e94\u8be5\u662f\u5c3e\u9012\u5f52\u7684\u3002<\/span> <span data-contrast=\"auto\">\u4f7f\u7528\u6b64\u5c5e\u6027\u6ce8\u91ca\u7684\u51fd\u6570\u5c06\u88ab\u68c0\u67e5\u662f\u5426\u786e\u5b9e\u662f\u5c3e\u9012\u5f52\uff0c\u5982\u679c\u4e0d\u662f\uff0c\u5219\u4f1a\u53d1\u51fa\u8b66\u544a<\/span><span data-contrast=\"auto\">\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5bf9\u8b66\u544a\u7684\u5206\u6790\u662f\u5728\u7f16\u8bd1\u5668\u7684\u4f18\u5316\u9636\u6bb5\u4e4b\u540e\u8fdb\u884c\u7684\uff0c\u56e0\u6b64\u8fd9\u65f6\u5019\u5bf9\u9012\u5f52\u51fd\u6570\u7684\u4efb\u4f55\u91cd\u5199\u90fd\u5df2\u5e94\u7528<\/span><span data-contrast=\"auto\">\u3002 <\/span><span data-contrast=\"auto\">\u5426\u5219\uff0c\u7f16\u8bd1\u5668\u53ef\u80fd\u4f1a\u5bf9\u4e00\u4e2a\u53ef\u4ee5\u91cd\u5199\u4e3a\u5faa\u73af\u7684\u51fd\u6570\u53d1\u51fa\u9519\u8bef\u8b66\u544a<\/span><span data-contrast=\"auto\">\u3002 <\/span><span data-contrast=\"auto\">\u5728\u5206\u6790\u8fc7\u7a0b\u4e2d\uff0c\u5c06\u904d\u5386\u7c7b\u578b\u5316\u62bd\u8c61\u8bed\u6cd5\u6811<\/span><span data-contrast=\"auto\"> (TAST)<\/span><span data-contrast=\"auto\">\uff0c\u5e76\u68c0\u67e5\u5bf9\u5177\u6709\u65b0\u5c5e\u6027\u7684\u51fd\u6570\u7684\u9012\u5f52\u8c03\u7528\u662f\u5426\u4ee5\u5c3e\u9012\u5f52\u65b9\u5f0f\u53d1\u751f\u3002<\/span><span data-contrast=\"auto\">\u4f8b\u5982\uff0c\u5e8f\u5217\u8868\u8fbe\u5f0f\u4e2d\u7684\u7b2c\u4e00\u4e2a\u4f4d\u7f6e\u4f1a\u5bfc\u81f4\u51fd\u6570\u8c03\u7528\u4e0d\u5177\u6709\u5c3e\u90e8\u9012\u5f52\u6027\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5c06\u8fd9\u4e2a\u65b0\u5c5e\u6027\u5e94\u7528\u4e8e<\/span><span data-contrast=\"auto\">countDown1\uff0c<\/span><span data-contrast=\"auto\">\u5982\u4e0b\u6240\u793a\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">[&lt;TailCall&gt;]\r\nlet rec countDown1 n =\r\n    if n = 0\r\n    then 0\r\n    else\r\n        countDown1 (n - 1) + 1<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u5bf9\u4e8e<\/span><span data-contrast=\"auto\"> F# 8<\/span><span data-contrast=\"auto\">\uff0c\u7f16\u8bd1\u5668\u4f1a\u9488\u5bf9\u51fd\u6570\u7684\u975e\u5c3e\u9012\u5f52\u5b9a\u4e49\u53d1\u51fa\u8b66\u544a\uff1a<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<pre class=\"prettyprint language-default\"><code class=\"language-default\">Program.fs(6,9): warning FS3569: The member or function 'countDown1' has the 'TailCallAttribute' attribute, but is not being used in a tail recursive way. [tailrec_blog.fsproj]<\/code><\/pre>\n<p><span data-contrast=\"auto\">\u501f\u52a9\u7f16\u8bd1\u5668\u7684\u8fd9\u4e00\u529f\u80fd\uff0c\u5f00\u53d1\u4eba\u5458\u5c06\u80fd\u591f\u66f4\u52a0\u4e13\u6ce8\u4e8e\u4ed6\u4eec\u7684\u5de5\u4f5c\u9886\u57df\uff0c\u800c\u4e0d\u5fc5\u62c5\u5fc3\u7f16\u8bd1\u4ee3\u7801\u7684\u6280\u672f\u7ec6\u8282\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><b><span data-contrast=\"auto\">\u81f4\u8c22<\/span><\/b><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u5b9e\u73b0\u6b64\u8b66\u544a\u662f\u8fc4\u4eca\u4e3a\u6b62\u6211\u5bf9<\/span><span data-contrast=\"auto\"> F# <\/span><span data-contrast=\"auto\">\u7f16\u8bd1\u5668\u7684\u6700\u5927\u8d21\u732e\u3002<\/span>\u00a0<span data-contrast=\"auto\">\u5728<\/span> <a href=\"http:\/\/pr\/\"><span data-contrast=\"auto\">PR<\/span><\/a> <span data-contrast=\"auto\">\u83b7\u5f97\u6279\u51c6\u4e4b\u524d\uff0c\u6211\u4e0d\u5f97\u4e0d\u5c1d\u8bd5\u4e0d\u540c\u7684\u65b9\u6cd5\u3002\u968f\u540e\u6211\u8fd8\u4fee\u590d\u4e86\u4e00\u4e9b\u9519\u8bef\uff0c\u8fd9\u4e9b\u9519\u8bef\u6ca1\u6709\u5728<\/span><span data-contrast=\"auto\"> .NET 8 <\/span><span data-contrast=\"auto\">\u4e2d\u5f97\u5230\u89e3\u51b3\uff0c\u4f46\u5e94\u8be5\u4f1a\u5728\u7b2c\u4e00\u4e2a\u8865\u4e01\u53d1\u5e03\u65f6\u5f97\u5230\u89e3\u51b3\u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p><span data-contrast=\"auto\">\u6211\u8981\u611f\u8c22\u4e00\u8def\u4e0a\u5e2e\u52a9\u8fc7\u6211\u7684\u6240\u6709\u4eba\uff0c\u4ee5\u53ca\u611f\u8c22<\/span><a href=\"https:\/\/github.com\/AviAvni\"><span data-contrast=\"none\">Avi Avni<\/span><\/a><span data-contrast=\"auto\">\u5728\u591a\u5e74\u524d\u5f00\u542f\u4e86\u6b64\u529f\u80fd\u7684\u7b2c\u4e00\u4e2a<\/span><a href=\"https:\/\/github.com\/dotnet\/fsharp\/pull\/1976\"><span data-contrast=\"none\">PR<\/span><\/a><span data-contrast=\"auto\"> \u3002<\/span><span data-ccp-props=\"{&quot;134245417&quot;:false,&quot;335551550&quot;:6,&quot;335551620&quot;:6}\">\u00a0<\/span><\/p>\n<p>\u5982\u679c\u5927\u5bb6\u6709\u4efb\u4f55\u7684\u6280\u672f\u95ee\u9898\uff0c\u6b22\u8fce\u5230\u6211\u4eec\u7684\u5b98\u65b9\u7684<a href=\"https:\/\/nam06.safelinks.protection.outlook.com\/?url=https%3A%2F%2Flearn.microsoft.com%2Fzh-cn%2Fanswers%2Ftags%2F97%2Fdotnet&amp;data=05%7C02%7CMia.Wu%40microsoft.com%7C15695dbaf2b34ad7714908dc1e4b2f56%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C638418555594657528%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&amp;sdata=qqzvO4%2BAMSHKLYvTs2tW0GH7nTcrr3CO6Em%2Fegnrie8%3D&amp;reserved=0\">.NET\u4e2d\u6587\u8bba\u575b<\/a> \u63d0\u95ee.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eDavid Schaefer\u7684Safer recursion in F#\u3002 \u8fd9\u662fDavid Schaefer\u7684\u5ba2\u5ea7\u535a\u5ba2\u6587\u7ae0\u3002David \u662f\u4e00\u540d\u4e13\u6ce8\u4e8e\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u81ea\u7531\u8f6f\u4ef6\u5f00\u53d1\u4eba\u5458\u3002\u4ed6\u662fG-Research\u5f00\u6e90\u56e2\u961f\u7684\u4e00\u5458\u3002\u4ed6\u81f4\u529b\u4e8e\u6539\u8fdb F# \u5f00\u53d1\u8005\u5de5\u5177\u7684\u751f\u6001\u7cfb\u7edf\u3002\u6b64\u5916\uff0c\u4ed6\u8fd8\u5e2e\u52a9\u7ef4\u62a4\u5404\u79cd\u5f00\u6e90\u7684 F# \u9879\u76ee\u3002 \u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\uff0c\u7528\u9012\u5f52\u7684\u65b9\u5f0f\u53bb\u5b9a\u4e49\u7b97\u6cd5\u662f\u5f88\u5e38\u89c1\u7684\u573a\u666f\u3002\u8fd9\u975e\u5e38\u7b26\u5408\u6211\u4eec\u60f3\u8981\u907f\u514d\u7a81\u53d8\u7684\u5fc3\u6001\uff0c\u800c\u4e14\u8fd9\u901a\u5e38\u4e0d\u4f1a\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002\u7f16\u8bd1\u5668\u5728\u4f18\u5316\u9636\u6bb5\u4f1a\u5c1d\u8bd5\u5c06\u9012\u5f52\u5b9a\u4e49\u91cd\u5199\u4e3a\u66f4\u9ad8\u6548\u7684\u5faa\u73af\u3002\u00a0 \u7136\u800c\uff0c\u7f16\u8bd1\u5668\u5e76\u4e0d\u603b\u662f\u80fd\u591f\u5c06\u9012\u5f52\u8f6c\u6362\u4e3a\u5faa\u73af\u3002\u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u5c31\u6709\u4e00\u5b9a\u7684\u5371\u9669\u4e86\u3002\u00a0 \u5806\u6808\u5e27\u4e0e\u751f\u4ea7\u73af\u5883\u00a0 \u5f53\u6211\u4eec\u5728\u51fd\u6570 f \u5185\u90e8\u8c03\u7528\u51fd\u6570 g \u65f6\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u901a\u5e38\u4f1a\u5728\u8fdb\u7a0b\u7684\u8c03\u7528\u5806\u6808\u4e0a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5806\u6808\u5e27\u3002\u51fd\u6570g\u5b8c\u6210\u540e\uff0c\u7a0b\u5e8f\u6b64\u65f6\u5c31\u4e0d\u518d\u9700\u8981\u5b83\u7684\u5806\u6808\u5e27\u4e86\uff0c\u4ece\u800c\u53ef\u4ee5\u91cd\u7528\u5b83\u7684\u7a7a\u95f4\u3002\u00a0 \u73b0\u5728\uff0c\u7406\u89e3\u5806\u6808\u5e27\u7684\u521b\u5efa\u5bf9\u4e8e\u9012\u5f52\u51fd\u6570\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u9012\u5f52\u8c03\u7528\uff0c\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5806\u6808\u5e27\u3002\u5728\u5f00\u53d1\u671f\u95f4\uff0c\u5f53\u89c4\u6a21\u8f83\u5c0f\u65f6\uff0c\u8fd9\u901a\u5e38\u4e0d\u4f1a\u5f15\u8d77\u95ee\u9898\u3002\u4f46\u5728\u540e\u671f\u7684\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u968f\u7740\u89c4\u6a21\u7684\u6269\u5927\uff0c\u7a0b\u5e8f\u4f1a\u56e0\u5806\u6808\u6ea2\u51fa\u800c\u7a81\u7136\u5d29\u6e83\u3002\u00a0 \u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u7531\u4e8e\u9012\u5f52\u8c03\u7528\u521b\u5efa\u4e86\u592a\u591a\u5806\u6808\u5e27\uff0c\u5806\u6808\u7684\u6240\u6709\u7a7a\u95f4\u90fd\u88ab\u7528\u5b8c\u4e86\uff0c\u6240\u4ee5runtime\u51b3\u5b9a\u505c\u6b62\u5b83\u3002 \u4e3a\u4e86\u6f14\u793a\u8fd9\u4e00\u573a\u666f\uff0c\u8bf7\u770b\u4e00\u4e0b\u8fd9\u4e2a\u9012\u5f52\u51fd\u6570\uff1a\u00a0 let rec countDown1 n = if n = 0 then 0 else countDown1 (n &#8211; 1) + 1 \u751f\u6210\u7684 IL \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a\u00a0 .method public static int32 countDown1 ( int32 n ) cil managed [&hellip;]<\/p>\n","protected":false},"author":99475,"featured_media":588,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[2,29],"class_list":["post-582","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet-ch","tag-net","tag-f"],"acf":[],"blog_post_summary":"<p>\u672c\u7bc7\u7ffb\u8bd1\u4e8eDavid Schaefer\u7684Safer recursion in F#\u3002 \u8fd9\u662fDavid Schaefer\u7684\u5ba2\u5ea7\u535a\u5ba2\u6587\u7ae0\u3002David \u662f\u4e00\u540d\u4e13\u6ce8\u4e8e\u51fd\u6570\u5f0f\u7f16\u7a0b\u7684\u81ea\u7531\u8f6f\u4ef6\u5f00\u53d1\u4eba\u5458\u3002\u4ed6\u662fG-Research\u5f00\u6e90\u56e2\u961f\u7684\u4e00\u5458\u3002\u4ed6\u81f4\u529b\u4e8e\u6539\u8fdb F# \u5f00\u53d1\u8005\u5de5\u5177\u7684\u751f\u6001\u7cfb\u7edf\u3002\u6b64\u5916\uff0c\u4ed6\u8fd8\u5e2e\u52a9\u7ef4\u62a4\u5404\u79cd\u5f00\u6e90\u7684 F# \u9879\u76ee\u3002 \u5728\u51fd\u6570\u5f0f\u7f16\u7a0b\u4e2d\uff0c\u7528\u9012\u5f52\u7684\u65b9\u5f0f\u53bb\u5b9a\u4e49\u7b97\u6cd5\u662f\u5f88\u5e38\u89c1\u7684\u573a\u666f\u3002\u8fd9\u975e\u5e38\u7b26\u5408\u6211\u4eec\u60f3\u8981\u907f\u514d\u7a81\u53d8\u7684\u5fc3\u6001\uff0c\u800c\u4e14\u8fd9\u901a\u5e38\u4e0d\u4f1a\u5bfc\u81f4\u6027\u80fd\u4e0b\u964d\u3002\u7f16\u8bd1\u5668\u5728\u4f18\u5316\u9636\u6bb5\u4f1a\u5c1d\u8bd5\u5c06\u9012\u5f52\u5b9a\u4e49\u91cd\u5199\u4e3a\u66f4\u9ad8\u6548\u7684\u5faa\u73af\u3002\u00a0 \u7136\u800c\uff0c\u7f16\u8bd1\u5668\u5e76\u4e0d\u603b\u662f\u80fd\u591f\u5c06\u9012\u5f52\u8f6c\u6362\u4e3a\u5faa\u73af\u3002\u4ece\u8fd9\u91cc\u5f00\u59cb\uff0c\u5c31\u6709\u4e00\u5b9a\u7684\u5371\u9669\u4e86\u3002\u00a0 \u5806\u6808\u5e27\u4e0e\u751f\u4ea7\u73af\u5883\u00a0 \u5f53\u6211\u4eec\u5728\u51fd\u6570 f \u5185\u90e8\u8c03\u7528\u51fd\u6570 g \u65f6\uff0c\u8fd9\u4e2a\u64cd\u4f5c\u901a\u5e38\u4f1a\u5728\u8fdb\u7a0b\u7684\u8c03\u7528\u5806\u6808\u4e0a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5806\u6808\u5e27\u3002\u51fd\u6570g\u5b8c\u6210\u540e\uff0c\u7a0b\u5e8f\u6b64\u65f6\u5c31\u4e0d\u518d\u9700\u8981\u5b83\u7684\u5806\u6808\u5e27\u4e86\uff0c\u4ece\u800c\u53ef\u4ee5\u91cd\u7528\u5b83\u7684\u7a7a\u95f4\u3002\u00a0 \u73b0\u5728\uff0c\u7406\u89e3\u5806\u6808\u5e27\u7684\u521b\u5efa\u5bf9\u4e8e\u9012\u5f52\u51fd\u6570\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u4e00\u822c\u6765\u8bf4\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u9012\u5f52\u8c03\u7528\uff0c\u90fd\u4f1a\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u5806\u6808\u5e27\u3002\u5728\u5f00\u53d1\u671f\u95f4\uff0c\u5f53\u89c4\u6a21\u8f83\u5c0f\u65f6\uff0c\u8fd9\u901a\u5e38\u4e0d\u4f1a\u5f15\u8d77\u95ee\u9898\u3002\u4f46\u5728\u540e\u671f\u7684\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u968f\u7740\u89c4\u6a21\u7684\u6269\u5927\uff0c\u7a0b\u5e8f\u4f1a\u56e0\u5806\u6808\u6ea2\u51fa\u800c\u7a81\u7136\u5d29\u6e83\u3002\u00a0 \u5728\u751f\u4ea7\u73af\u5883\u4e2d\uff0c\u7531\u4e8e\u9012\u5f52\u8c03\u7528\u521b\u5efa\u4e86\u592a\u591a\u5806\u6808\u5e27\uff0c\u5806\u6808\u7684\u6240\u6709\u7a7a\u95f4\u90fd\u88ab\u7528\u5b8c\u4e86\uff0c\u6240\u4ee5runtime\u51b3\u5b9a\u505c\u6b62\u5b83\u3002 \u4e3a\u4e86\u6f14\u793a\u8fd9\u4e00\u573a\u666f\uff0c\u8bf7\u770b\u4e00\u4e0b\u8fd9\u4e2a\u9012\u5f52\u51fd\u6570\uff1a\u00a0 let rec countDown1 n = if n = 0 then 0 else countDown1 (n &#8211; 1) + 1 \u751f\u6210\u7684 IL \u4ee3\u7801\u5982\u4e0b\u6240\u793a\uff1a\u00a0 .method public static int32 countDown1 ( int32 n ) cil managed [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/582","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/users\/99475"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/comments?post=582"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/posts\/582\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media\/588"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/media?parent=582"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/categories?post=582"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet-ch\/wp-json\/wp\/v2\/tags?post=582"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}