Unix tail in haskell I am trying to write a simple version of the unix tail utility in haskell to improve my understanding of monads. Here is what I have now. I am pretty sure that this is not quite "Haskell enough" yet. Can you please help me improve my code?

import System.Environment
import System.Exit
import Control.Monad

main = getArgs &gt;&gt;= (parse' (10, [])) &gt;&gt;= \ (n_lines, ss) -&gt;
        putStr $ concatMap (tailFile n_lines) ss

tailFile :: Int -&gt; (FilePath, String) -&gt; String
tailFile n_lines (f, c) =
    "==&gt; " ++ f ++ " &lt;==\n" ++
    (unlines.reverse.(take n_lines).reverse.lines) c

parse' :: (Int, [(FilePath, String)])
            -&gt; [String]
            -&gt; IO (Int, [(FilePath, String)])
parse' _ ("-h":_) = putStrLn "usage: " &gt;&gt; exit
parse' _ ("-v":_) = putStrLn "version: 0.1" &gt;&gt; exit
parse' (_, ss) ("-n":num:f) = parse' (read num, ss) f
parse' (n, ss) (f:fs) = do
                            contents &lt;- readFile f
                            parse' (n, ss ++ [(f,contents)]) fs
parse' (x, ss) [] = return (x, ss)


exit = exitWith ExitSuccess
die = exitWith (ExitFailure 1)
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