* cat by foldM [#o471dc62]
[[foldM:http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Monad.html#v%3AfoldM]]を使ってcat。引数に与えられたファイルを結合して標準出力に流し込みます。


 import Control.Monad(foldM)
 import System.Environment(getArgs)
 
 -- readFile :: FilePath -> IO String
 -- getArgs :: IO [String]
 -- foldM :: Monad m => (a -> b -> m a) -> a -> [b] -> m a
 
 freadAppend :: String -> FilePath -> IO String
 freadAppend x f = do
   str <- readFile f
   return $ x++str
 
 main :: IO ()
 main = do
   files <- getArgs
   str <- foldM freadAppend "" files
   putStrLn str

トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS