Timing out pure functions

橙三吉。 提交于 2019-12-03 22:25:56

The point is that

return (fact 999999999)

immediately returns and doesn't trigger the timeout. It returns a thunk that will be evaluated later.

If you force evaluation of the return value,

main = do maybeNum <- timeout (10 ^ 7) $ return $! fact 99999999
          print maybeNum

it should trigger the timeout (if you provide a stack large enough so that the timeout happens before the stack overflow).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!