テキストファイルのリストを引数として取り、各行がファイル内の対応する行間のタブのインターカレーションであるファイルを出力するプログラムを書いています。
すべての文字が ASCII エンコードされていると仮定します
import GHC.IO.Handle
import System.IO
import System.Environment
import Data.List
main = do
(out:files) <- getArgs
hs <- mapM (`openFile` ReadMode) files
txts <- mapM B.hGetContents hs
let final = map (B.intercalate (B.singleton '\t')) . transpose
. map (B.lines . B.filter (/= '\t')) $ txts
withFile out WriteMode $ \out ->
B.hPutStr out (B.unlines final)
putStrLn "Completed successfully"
問題は、次のように出力されることです。
file1row1
file2row1
file1row2
file2row2
file1row3
file2row3
それ以外の:
file1row1 file2row1
file1row2 file2row2
file1row3 file2row3
ghci で関数を手動で定義してテストすると、同じロジックが正しく機能します。Data.Text.Lazyまた、 lazy の代わりに使用すると、同じコードが正しく機能しBytestringます。
私のアプローチの何が問題になっていますか?