<div style="min-height:22px;margin-bottom:8px;">In general infinite monadic recursion will leak, since the tail position is always >> or >>= instead of your own recursive function, but under certain situations, e.g. IO without arguments, the compiler will figure there's no need to push new stack frame. But anyway it's better to checkout yourself rather relying on some weak assumptions.</div><div style="min-height:22px;margin-bottom:8px;"><br></div><span class="mail-footer" aria-hidden="true">·¢×ÔÎÒµÄiPhone</span><div id="original-content"><br><br><div><div style="font-size:70%;padding:2px 0;">------------------ Original ------------------</div><div style="font-size:70%;background:#f0f0f0;color:#212121;padding:8px;border-radius:4px"><div><b>From:</b> §¯§Ú§Ü§Ú§ä§Ñ §¶§å§æ§Ñ§Ö§Ó <kitttoran@gmail.com></div><div><b>Date:</b> Wed,Jun 20,2018 2:37 AM</div><div><b>To:</b> haskell-cafe <haskell-cafe@haskell.org></div><div><b>Subject:</b> Re: [Haskell-cafe] Memory leak in infinite recursion</div></div></div><br><div dir="ltr">Hello everyone<br><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> mainLoopModeA</div><div>mainLoopModeB = do</div><div> doSomethingElse</div><div> when anotherCondition mainLoopModeA</div><div> mainLoopModeB</div><div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"><br>or this case?</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 mainLoopModeA</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"> then mainLoopModeA</div><div style="font-size:small;text-decoration-style:initial;text-decoration-color:initial"> else mainLoopModeB</div></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>
</div>