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。而是,第二个示例挂起。