<div dir="ltr">Actually, after reading the question again, it seems like my response wasn't quite right. You are not actually building the list. In that case, I am as confused as you. :)<div><br></div><div>Sorry!</div></div><br><div class="gmail_quote"><div dir="ltr">Am So., 18. Nov. 2018 um 01:51 Uhr schrieb Daniel Díaz Casanueva <<a href="mailto:dhelta.diaz@gmail.com">dhelta.diaz@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr">Hello Ryan.<div><br></div><div>Try evaluating the expression to normal form instead of weak head normal form in your expression. So:</div><div><br></div><div>>>> timeout 1 $ evaluate $ force $ let x = 0 : x in last x<br></div><div><br></div><div>The function `force` comes from the deepseq package. You can read the docs here: <a href="http://hackage.haskell.org/package/deepseq-1.4.4.0/docs/Control-DeepSeq.html" target="_blank">http://hackage.haskell.org/package/deepseq-1.4.4.0/docs/Control-DeepSeq.html</a></div><div><br></div><div>I hope that helps.</div><div><br></div><div>Best regards,</div><div>Daniel</div></div></div><br><div class="gmail_quote"><div dir="ltr">Am So., 18. Nov. 2018 um 00:22 Uhr schrieb Ryan Reich <<a href="mailto:ryan.reich@gmail.com" target="_blank">ryan.reich@gmail.com</a>>:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div dir="ltr"><div>I want to time out a pure computation.  My experience, and that described in various previous questions here and elsewhere (the best of which is <a href="https://mail.haskell.org/pipermail/haskell-cafe/2011-February/088820.html" target="_blank">https://mail.haskell.org/pipermail/haskell-cafe/2011-February/088820.html</a>), is that this doesn't always work: for instance,</div><div><br></div><div>>>> timeout 1 $ evaluate $ let x = 0 : x in last x</div><div><br></div><div>does not time out because, apparently, the fact that the expression evaluates in constant space (i.e. never allocates) means that it never yields to the timeout monitor thread that would kill it.</div><div><br></div><div dir="ltr">The solution that is described in the other iterations is to embed checkpoints in the expression that do allocate, giving the RTS a chance to switch contexts.  However, in my application, the expression is /arbitrary/ and I do not have the freedom to inject alterations into it.  (Don't argue this point, please.  The expression is arbitrary.)<div><br></div><div>How can I time out a tight loop like the above?  Clearly, it can be done, because I can, say, alt-tab over to another terminal and kill the process, which exploits the operating system's more aggressively pre-emptive scheduling.  Is there a solution using bound threads, say 'forkOS' instead of 'forkIO' in the implementation of 'timeout'?  Unix signals?  Some FFI-based workaround?  Etc.  Keep in mind that notwithstanding that comment, I don't actually want to kill the whole process, but just the one evaluation.<br></div><div><br></div><div>Thanks in advance,</div><div>Ryan Reich<br></div></div></div></div>
_______________________________________________<br>
Haskell-Cafe mailing list<br>
To (un)subscribe, modify options or view archives go to:<br>
<a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe" rel="noreferrer" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe</a><br>
Only members subscribed via the mailman list are allowed to post.</blockquote></div>
</blockquote></div>