Skip to content

Instantly share code, notes, and snippets.

@KirinDave
Created November 21, 2011 18:45
Show Gist options
  • Save KirinDave/1383510 to your computer and use it in GitHub Desktop.
Save KirinDave/1383510 to your computer and use it in GitHub Desktop.
halp :: Int -> IO [Int]
halp 0 = return []
halp a = do
putStrLn "Tick in IO [Int]"
y <- halp (a - 1)
return $ 1 : y
halphalp :: Int -> [IO Int]
halphalp n = replicate n $ (putStrLn "Tick in [IO Int]" >> return 1)
main = do
putStrLn "The behavior of IO [Int]"
x <- halp 5
putStrLn (show $ head x)
-- We saw 5 ticks but printed only the first value.
putStrLn "The behavior of [IO Int]"
let y = halphalp 5 -- Note that this is a let, not a do!
z <- head y -- Now let's execute ONE of these.
putStrLn (show z) -- We only saw one tick.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment