Created
March 18, 2016 14:07
-
-
Save JohnL4/76667683600854c21f47 to your computer and use it in GitHub Desktop.
Example of an unused IO operation in a "do" block executed regardless of the fact that it's unused
This file contains 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
import System.IO | |
main = do | |
inText <- getContents | |
let inWords = words inText | |
result <- f ( read (inWords !! 0) :: Int) | |
putStrLn result | |
f :: Int -> IO String | |
f x = do | |
h <- openFile "lazyfileplay-out.txt" WriteMode -- This seems to cause the file to be touched regardless of the fact | |
-- that it's not actually used. Is it because the "do" block just | |
-- executes everything regardless, as opposed to lazily-binding things | |
-- and only executing them when needed? | |
return $ if x == 1 then "1" else "not 1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment