条件を満たす行を取り除く
今回は条件を満たす行を取り除くに挑戦。
最初に書いたのはこれでした。
main = do cs <- getContents putStr $ unlines $ filter match $ lines cs where match :: String -> Bool match [] = True match s = if head s == '#' then False else True
投稿されているプログラムを見て、パターンマッチが使えるということに気付いて書き直したのがこれ。こっちの方がすっきりしています。
main = do cs <- getContents putStr $ unlines $ filter match $ lines cs where match :: String -> Bool match ('#':_) = False match _ = True
いずれにしてもmatchで条件にマッチしている方をFalseにしているのがいまいちだなという感じ。