Created
August 31, 2011 06:23
-
-
Save maoe/1182930 to your computer and use it in GitHub Desktop.
lazy I/Oで出力の順番が意図したとおりにならない例
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
module Main where | |
import System.IO.Unsafe (unsafeInterleaveIO) | |
test f = do | |
line1 <- f | |
line2 <- f | |
putStrLn $ "line2: " ++ line2 | |
putStrLn $ "line1: " ++ line1 | |
main :: IO () | |
main = do | |
putStrLn "lazy" | |
test $ unsafeInterleaveIO getLine | |
putStrLn "strict" | |
test getLine |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
% ./UnsafeIO
lazy
aaa
line2: aaa
bbb
line1: bbb
strict
aaa
bbb
line2: bbb
line1: aaa