関数型プログラミング言語Haskell Part8

70デフォルトの名無しさん
お前ら
コマンドライン引数から複数のテキストファイル名を取得してその中身を標準出力に出力するプログラム書いてみてくれ
IO [String]が…[]外れねぇよチクショウorz
71デフォルトの名無しさん:2007/11/09(金) 21:22:15
import System.Environment

main = do
  args <- getArgs
  mapM_ dump args
  where
    dump file = do
      content <- readFile file
      putStr content

こんなの?
72デフォルトの名無しさん:2007/11/09(金) 21:30:54
そんなの…

俺とてつもなく頭悪い気がしてきた('A`)
73デフォルトの名無しさん:2007/11/09(金) 23:45:24
>>71 のを短く書けばこんな感じ

import System.Environment
main = getArgs >>= mapM_ ((putStr =<<) . readFile)
74デフォルトの名無しさん:2007/11/10(土) 01:57:22
>>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みたいに便利な関数は早く標準ライブラリに入れてほしい