2013年12月16日月曜日

開発環境

初めてのコンピュータサイエンス(Jennifer CampbellPaul GriesJason MontojoGreg Wilson(著)長尾 高弘(翻訳))の12章(各種ツール)、12.7(練習問題)、12-12.をHaskellで解いてみる。

その他参考書籍

12.7(練習問題)、12-12.

コード(BBEdit)

Sample.hs

{-# OPTIONS -Wall -Werror #-}

main :: IO ()
main =  mapM_ print $ map (\(s, n) -> (length $ lines s) == n)
                          testStrings

testStrings :: [(String, Int)]
testStrings = [("", 0),
               ("python", 1),
               ("python\n\
                \haskell\n\
                \", 2),
               ("python\n\
                \haskell\n\
                \ ", 3),
               ("\n\
                \\n\
                \\n\
                \ ", 4),
               ("\n\n\n\n\n", 5)]

入出力結果(Terminal, runghc)

$ runghc Sample.hs
True
True
True
True
True
True
$

慣れるまでは{-# OPTIONS -Wall -Werror #-}の記述を消さずに細かく型を指定していくことに。

0 コメント:

コメントを投稿