2007-09-01から1ヶ月間の記事一覧

入門 Haskell 練習問題 1.6

1. wordScan を使って inQuote を再実装 wordsCount str = outWords str where outWords str = wordScan (\n -> 1 + n) str inWords str = wordScan id str inQuote (c:cs) | c == '\'' = outWords cs | otherwise = inQuote cs wordScan f [] = 0 wordScan …

入門 Haskell 練習問題 1.5

1. 空白行を数えない linesCount linesCount str = linesFirst str where linesFirst [] = 0 linesFirst (c:cs) | c == '\n' = linesFirst cs | otherwise = linesLast cs linesLast [] = 0 linesLast (c:cs) | c == '\n' = 1 + linesFirst cs | otherwise =…