<div dir="auto"><div>Actually, only the second set is tail recursive. The first set could be trouble.<br><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 19, 2018, 8:03 PM Mark Wotton <<a href="mailto:mwotton@gmail.com">mwotton@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Any mutually recursive set of functions calling in tail position should be fine - all your examples are ok.<div><br><div class="gmail_quote"><div dir="ltr">On Tue, Jun 19, 2018, 2:37 PM Никита Фуфаев <<a href="mailto:kitttoran@gmail.com" target="_blank" rel="noreferrer">kitttoran@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><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="m_-1677067646919702083m_4562916073905413812gmail-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="m_-1677067646919702083m_4562916073905413812gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div dir="ltr"><div dir="ltr">Nikita Fufaev<br></div></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 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></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 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></div></div>