YAMAGUCHI::weblog

海水パンツとゴーグルで、巨万の富を築きました。カリブの怪物、フリーアルバイター瞳です。

ふつうのHaskellプログラミング 第7章 練習問題

  • fold.hs
foldCol = 61

main = do cs <- getContents
          putStr $ unlines $ map foldLineAt $ lines cs

foldLineAt :: String -> String
foldLineAt cs = case snd (splitAt foldCol cs) of
                  [] -> cs
                  (c1:cs1) -> if length cs1 >= (foldCol - 1)
                              then foldLineAt cs1
                              else fst (splitAt foldCol cs) ++ "\n" ++ snd (splitAt foldCol cs)

どうもソースが汚いなぁ。もっと綺麗に書けるように練習しないと。どうも条件分岐の処理がへたくそな気がする。