[Haskell-cafe] Memory leak in infinite recursion

Никита Фуфаев kitttoran at gmail.com
Tue Jun 19 18:36:50 UTC 2018


Hello everyone

In C you can't implement main loop with recursion like
void mainLoop() {
  doSomething();
  mainLoop();
}
because without optimisations stack will overflow.
In haskell it's common to write
mainLoop = 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 ExitSuccess
What about this case?
mainLoopModeA = do
  doSomething
  when condition mainLoopModeB
  mainLoopModeA
mainLoopModeB = do
  doSomethingElse
  when anotherCondition mainLoopModeA
  mainLoopModeB

or this case?
mainLoopModeA = do
  doSomething
  if condition
    then mainLoopModeB
    else mainLoopModeA
mainLoopModeB = do
  doSomethingElse
  if anotherCondition
    then mainLoopModeA
    else mainLoopModeB

-- 
Nikita Fufaev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20180619/6208a6be/attachment.html>


More information about the Haskell-Cafe mailing list