Data.FiniteMap はもう無い
All About Monads (文字化け注意) の example4.hs が実行できない。
使われている Data.FiniteMap と、それ関連の関数が古いらしい。今は、Data.Map を使うらしい。
次のように修正したら動いた。
--- 24行目 - import Data.FiniteMap + import Data.Map --- 51行目 - type Dict = FiniteMap String String + type Dict = Map String String --- 55行目 - addEntry d e = addToFM d (key e) (value e) + addEntry d e = insert (key e) (value e) d --- 60行目 - entries <- return (map read (lines contents)) + entries <- return (Prelude.map read (lines contents)) --- 68行目 - dict <- foldM addDataFromFile emptyFM handles + dict <- foldM addDataFromFile empty handles --- 69行目 - print (fmToList dict) + print (toList dict)
60行目 map が名前衝突をおこすので、Prelude.map と モジュール名を付けて解決。それ以外は同じ機能の関数で置き換え。
実行するには適当にデータファイルを作って
$ cat hoge.txt foo=100 bar=hello, world buz= 123 456
引数にあたえて実行
$ runghc example4.hs hoge.txt [("bar","hello, world"),("buz","123 456"),("foo","100")]
コンパイルする時はモジュールをリンクするために --make オプションが必要
$ ghc --make example4.hs
$ ./example4 hoge.txt [("bar","hello, world"),("buz","123 456"),("foo","100")]