小编Pet*_*hte的帖子

如何使用Haskell超时功能(在System.Timeout中)停止失控计算?

System.Timeout中的超时功能有时无法停止无限计算。

例如,

timeout 1000 $ print $ length [0..]
Run Code Online (Sandbox Code Playgroud)

Nothing由于超时中断了无限计算,因此按预期返回。但

timeout 1000 $ print $ length $ cycle [1,2,3]
Run Code Online (Sandbox Code Playgroud)

永远循环。

在Mac上,使用ghc或ghci 8.6.4。

我希望第二个示例的行为与第一个示例相同,在1毫秒后中断无限计算并返回Nothing。而是,第二个示例挂起。

haskell timeout infinite infinite-loop

9
推荐指数
1
解决办法
144
查看次数

标签 统计

haskell ×1

infinite ×1

infinite-loop ×1

timeout ×1