関数型プログラミング言語Haskell Part8
お前ら
コマンドライン引数から複数のテキストファイル名を取得してその中身を標準出力に出力するプログラム書いてみてくれ
IO [String]が…[]外れねぇよチクショウorz
import System.Environment
main = do
args <- getArgs
mapM_ dump args
where
dump file = do
content <- readFile file
putStr content
こんなの?
そんなの…
俺とてつもなく頭悪い気がしてきた('A`)
>>71 のを短く書けばこんな感じ
import System.Environment
main = getArgs >>= mapM_ ((putStr =<<) . readFile)
>>71のをArrowで書けばこんな感じ
mapA :: ArrowChoice a => a b c -> a [b] [c]
mapA f = arr listcase >>>
arr (const []) ||| (f *** mapA f >>> arr (uncurry (:)))
where
listcase [] = Left ()
listcase (x:xs) = Right (x,xs)
main :: IO ()
main = runKleisli (Kleisli (const getArgs) >>> mapA (Kleisli readFile) >>> arr concat >>> Kleisli putStr) ()
-- mapAみたいに便利な関数は早く標準ライブラリに入れてほしい