<div dir="ltr">Hello everyone<br clear="all"><div><br></div><div>In C you can't implement main loop with recursion like</div><div>void mainLoop() {</div><div> doSomething();</div><div> mainLoop();</div><div>} </div><div>because without optimisations stack will overflow.</div><div>In haskell it's common to write</div><div>mainLoop = doSomething >> mainLoop, and it doesn't leak memory because of haskell's evaluation model.</div><div>Does memory leak or argument stack overflow happen in this case?</div><div>mainLoop = doSomething >> mainLoop >> exit ExitSuccess</div><div>What about this case?</div><div>mainLoopModeA = do</div><div> doSomething</div><div> when condition mainLoopModeB</div><div> <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">mainLoopModeA</span></div><div>mainLoopModeB = do</div><div> doSomethingElse</div><div> when anotherCondition <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">mainLoopModeA</span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> <span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">mainLoopModeB</span></span></div><div><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br class="gmail-Apple-interchange-newline"><span style="background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">or this case?</span></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">mainLoopModeA = do</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"> doSomething</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"> if condition</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"> then mainLoopModeB</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"> else <span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">mainLoopModeA</span></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial">mainLoopModeB = do</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"> doSomethingElse</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"> if anotherCondition </div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> then mainLoopModeA</span></div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><span style="font-size:small;background-color:rgb(255,255,255);text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline"> else <span style="text-decoration-style:initial;text-decoration-color:initial;float:none;display:inline">mainLoopModeB</span></span></div></span></span></div><br>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr">Nikita Fufaev<br></div></div></div></div>
</div>