f# stackoverflow project euler #4

前端 未结 2 476
太阳男子
太阳男子 2020-12-19 21:09

I\'m working on problem four of Project Euler and am running into a stackoverflow exception. I\'m not asking for help on solving the problem, I\'d just like it explained

相关标签:
2条回答
  • 2020-12-19 21:47

    I can't read F# and don't know if your problem is related to this but especially if you're doing something recursive avoid checking for equality to a number, instead try to check for a threshold. For example, instead of testing n = 0, test n <= 0.

    0 讨论(0)
  • 2020-12-19 21:57

    Are you compiling in 'Debug' mode or 'Release' mode? Debug mode in VS has tail calls turned off by default (compiler flag "--tailcalls-"), in order to preserve stacks for debugging, but this has the trade-off that you may StackOverflow. You can either switch to 'Release' mode, or

    • right-click the project properties in Solution Explorer, select 'Properties'
    • go to the 'Build' tab
    • make sure 'Debug' configuration is selected
    • click the box 'Generate tail calls'

    to turn on tail calls with 'Debug' settings.

    (Your program runs fine for me with tail calls enabled.)

    0 讨论(0)
提交回复
热议问题