Oops, yes, you are right - if it keeps switching back and forth the stack will build up. Apologies, written while wrangling a toddler.
Actually, only the second set is tail recursive. The first set could be trouble.On Tue, Jun 19, 2018, 8:03 PM Mark Wotton <mwotton@gmail.com> wrote:Any mutually recursive set of functions calling in tail position should be fine - all your examples are ok._______________________________________________On Tue, Jun 19, 2018, 2:37 PM Никита Фуфаев <kitttoran@gmail.com> wrote:Hello everyone_______________________________________________In C you can't implement main loop with recursion likevoid mainLoop() {doSomething();mainLoop();}because without optimisations stack will overflow.In haskell it's common to writemainLoop = doSomething >> mainLoop, and it doesn't leak memory because of haskell's evaluation model.Does memory leak or argument stack overflow happen in this case?mainLoop = doSomething >> mainLoop >> exit ExitSuccessWhat about this case?mainLoopModeA = dodoSomethingwhen condition mainLoopModeBmainLoopModeAmainLoopModeB = dodoSomethingElsewhen anotherCondition mainLoopModeAmainLoopModeB
or this case?mainLoopModeA = dodoSomethingif conditionthen mainLoopModeBelse mainLoopModeAmainLoopModeB = dodoSomethingElseif anotherConditionthen mainLoopModeAelse mainLoopModeB
--Nikita Fufaev
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.