2010-07-01から1ヶ月間の記事一覧

newtype を作ってみる

やさしい Haskell 入門 (バージョン 98 ) 6 再び、型について 6.1 Newtype 宣言 を参考に newtype を作ってみます。 newtype Age = Age Integer deriving (Eq, Read, Show) toAge :: Integer -> Age toAge x | x < 0 = error "Can't create negative age!" |…

Data.HashTableを使ってみる。

Data.HashTable new (key -> key -> Bool) -> (key -> Int32) -> IO (HashTable key val) 新しいハッシュ表を作る。最初の引数は key を比較する関数、2番目の引数は key を Int32 に変換する関数。(Int 用の hashInt、文字列用の hashString がある。) 参…

数値(Numeric):読み込み関数

The Haskell 98 Report 14 数値 14.2 読み込み関数 lexDigits :: ReadS String は 10 進数の空ではない文字列を読み込む。 > :m + Numeric > :t lexDigits --=> lexDigits :: String -> [(String, String)] > lexDigits "12345" --=> [("12345","")] > lexDi…

Data.List.Split を使ってみる。

Data.List.Split はリストを分割するためのライブラリです。 インストール は cabal install split で OK。 > cabal install split Resolving dependencies... Downloading split-0.1.2... Configuring split-0.1.2... (snip) Reading package info from "di…

「Real World Haskell」読書メモ 7.入出力 7.1 Haskellにおける古典的入出力

return は純粋な値を IO アクションでくるんで返す。 Prelude> :t "Hello,world!" "Hello,world!" :: [Char] Prelude> :t return "Hello,world!" return "Hello,world!" :: (Monad m) => m [Char] Prelude> h <- return "Hello,world!" Prelude> :t h h :: […