Unix tail in haskell
My first approach is to map the arguments to a list of IO actions and then execute them:

import Control.Monad
import System.Environment

lastLines :: Int -&gt; String -&gt; [String]
lastLines n = reverse.take n.reverse.lines

printLines :: [String] -&gt; IO ()
printLines = flip forM_ $ putStrLn

readLastLines :: Int -&gt; FilePath -&gt; IO [String]
readLastLines n f = readFile f &gt;&gt;= return . (++) ["==&gt;" ++ f ++ "&lt;=="] . lastLines n

argsToActions :: [String] -&gt; [IO ()]
argsToActions ("-h":_) = [print "Usage"]
argsToActions ("-v":_) = [print "V 1.0"]
argsToActions ("-n":n:f:_) = [readLastLines (read n) f &gt;&gt;= printLines]
argsToActions (f:fs) = [readLastLines 10 f &gt;&gt;= printLines] ++ argsToActions fs
argsToActions [] = []

main :: IO ()
main = getArgs &gt;&gt;= sequence_ . argsToActions