Skip to content

Memory leak caused by nested monadic loops

See this stackoverflow post: http://stackoverflow.com/a/41521876/110081

Basically, the following program leaks memory on ghc 7.10.3 and ghc 8.0.1.

import Control.Monad (forever)

main :: IO ()
main = worker

{-# NOINLINE worker #-}
worker :: (Monad m) => m ()
worker = forever $ poll ()

poll :: (Monad m) => () -> m a
poll action = do
    return ()
    poll action

Could ghc do better there?

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
Edited by Feuerbach
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information