Skip to content

Instantly share code, notes, and snippets.

@davidallsopp
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save davidallsopp/ee94db72edf46052cec3 to your computer and use it in GitHub Desktop.

Select an option

Save davidallsopp/ee94db72edf46052cec3 to your computer and use it in GitHub Desktop.
Looping forever with a recursive main. Haskell IO is often explained in terms of main returning an IO value then being executed by the runtime, but it's less clear what goes on when main apparently never terminates. See https://stackoverflow.com/questions/28203214/why-how-does-recursive-io-work
module Forever where
main :: IO ()
main = do
line <- getLine
putStrLn line
main
-- or if you prefer point-free style:
main2 :: IO ()
main2 = getLine >>= putStrLn >> main2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment