Last active
August 29, 2015 14:14
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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