使用 F# 的递归函数和断点

发布于 2024-12-07 11:37:19 字数 1571 浏览 0 评论 0原文

考虑以下代码:

[<EntryPoint>]
let main (args: string []) = 

  let rec main time =
    let newTime = time + 2 // place a breakpoint at this line
    main newTime

  main 0

我无法在标记行处放置断点。我在使用递归函数时经常遇到这样的问题,这真的让我不想使用它们。有什么简单的解决方案吗?

编辑:我创建一个全新的解决方案,我的构建命令如下所示:

'------ 构建开始:项目:ConsoleApplication4,配置:调试 x86 ------ C:\Program Files (x86)\Microsoft F#\v4.0\fsc.exe -o:obj\x86\Debug\ConsoleApplication4.exe -g --debug:full --noframework --define:DEBUG --define: TRACE --doc:bin\Debug\ConsoleApplication4.XML --optimize- --tailcalls- --platform:x86 -r:"C:\Program Files (x86)\Reference程序集\Microsoft\FSharp\2.0\Runtime\v4.0\FSharp.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\ mscorlib.dll" -r:"C:\Program Files (x86)\Reference程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\ Client\System.dll" -r:"C:\Program Files (x86)\Reference程序集\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Numerics.dll" --target:exe --warn:3 --warnaserror:76 --vserrors --LCID:1033 --utf8output --完整路径--扁平错误“C:\ Users \ olsv \ AppData \ Local \ Temp.NETFramework,版本= v4.0,配置文件= Client.AssemblyAttributes.fs” Program.fs 控制台应用程序4 -> d:\olsv\documents\Visual Studio 2010\Projects\ConsoleApplication4\ConsoleApplication4\bin\Debug\ConsoleApplication4.exe ========== 构建:1 成功或最新,0 失败,0 跳过 =========='

Consider the following code:

[<EntryPoint>]
let main (args: string []) = 

  let rec main time =
    let newTime = time + 2 // place a breakpoint at this line
    main newTime

  main 0

I am not able to place a breakpoint at the marked line. I meet such problems quite often when using recursive functions and it really makes me not to use them. Is there any simple solution for that?

EDIT: I create a brand new solution and my build command looks like:

'------ Build started: Project: ConsoleApplication4, Configuration: Debug x86 ------
C:\Program Files (x86)\Microsoft F#\v4.0\fsc.exe -o:obj\x86\Debug\ConsoleApplication4.exe -g --debug:full --noframework --define:DEBUG --define:TRACE --doc:bin\Debug\ConsoleApplication4.XML --optimize- --tailcalls- --platform:x86 -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\2.0\Runtime\v4.0\FSharp.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\mscorlib.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Core.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.dll" -r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\Profile\Client\System.Numerics.dll" --target:exe --warn:3 --warnaserror:76 --vserrors --LCID:1033 --utf8output --fullpaths --flaterrors "C:\Users\olsv\AppData\Local\Temp.NETFramework,Version=v4.0,Profile=Client.AssemblyAttributes.fs" Program.fs
ConsoleApplication4 -> d:\olsv\documents\visual studio 2010\Projects\ConsoleApplication4\ConsoleApplication4\bin\Debug\ConsoleApplication4.exe
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped =========='

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

瑾夏年华 2024-12-14 11:37:19

我尝试调试您发布的代码,它似乎工作得很好(我使用的是 Visual Studio 2010 SP1)。当我放置断点并运行代码(作为控制台应用程序)时,它会重复在断点处停止,我可以单步执行到下一个表达式并查看局部变量的状态。

您可以尝试检查编译器标志 - 当您禁用优化和尾部调用时,调试效果最好(这可能与递归函数特别相关)。当我构建项目时,标志包括以下内容:--debug:full --optimize- --tailcalls-

在此处输入图像描述

I tried debugging the code you posted and it seems to be working just fine (I'm using Visual Studio 2010 SP1). When I place the breakpoint and run the code (as a console application) it stops at the breakpoint repeatedly and I can step to the next expression and see the state of local variables.

You could try checking compiler flags - the debugging works the best when you disable optimizations and tail-calls (this may be particularly relevant to recursive functions). When I build the project, the flags include the following:--debug:full --optimize- --tailcalls-.

enter image description here

方觉久 2024-12-14 11:37:19

所以看起来,这是一个错误。我已经向 F# 团队报告了。所以我们希望他们能尽快修复它!

So it looks like, that it is a bug. I have already reported it to the F# team. So lets hope that they will fix it soon!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文