{-# LANGUAGE RankNTypes #-} module ExamplesIO where import List -- No IO involved in the type, no side-effects then. f1 :: Eq a => a -> [a] -> ([a], Bool) f1 x xs = (take 10 (cycle xs), elem x xs) -- Here, the type returns an IO Bool. Observe that -- the IO computations can do whatever side-effect before -- returning the actual boolean value. -- -- Once we know it is an IO computation, all the bets are off -- if it comes from untrustworthy code! f2 :: (Show a, Eq a) => Int -> a -> ([a], IO Bool) f2 n x = (take n (iterate id x), do putStrLn "Hi!" putStrLn "The arguments of the function are" putStrLn $ "x = " ++ show x putStrLn $ "n = " ++ show n return True )