Created
July 13, 2012 16:49
-
-
Save dtjm/3105934 to your computer and use it in GitHub Desktop.
The Cat in the Haskell
This file contains hidden or 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
import Control.Monad as Monad | |
import System.Exit | |
import System.IO as IO | |
import System.Environment as Env | |
main :: IO () | |
main = do | |
-- Get the command line arguments | |
args <- Env.getArgs | |
-- If we have arguments, read them as files and output them | |
if (length args > 0) then catFileArray args | |
-- Otherwise, output stdin to stdout | |
else catHandle stdin | |
catFileArray :: [FilePath] -> IO () | |
catFileArray = Monad.mapM_ catFile | |
catFile :: FilePath -> IO () | |
catFile f = openFile f ReadMode >>= catHandle | |
catHandle :: Handle -> IO () | |
catHandle h = hGetContents h >>= putStr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
http://stackoverflow.com/questions/11475006/how-do-i-implement-cat-in-haskell/11475445#11475445