関数型言語 Gofer |
作成日:2008-04-14 最終更新日: |
Gofer は、Haskell の教育用言語、と Wikipedia (英語版)には書かれている。また、名称の由来は "Good For Equational Reasoning" として同じく Wikipedia に解説されている。 わたしが持っている Gofer の本は、 武市正人先生の「プログラミング言語」(以下、本と称する)だけである。
上述の通り、Gofer をインストールするというより、 Haskell の処理系 ghc や ghci で、 「プログラミング言語」の例を検証しようと思う。
以下、本の第2章を追う。
ページ | 内容 | Gofer | Haskell |
---|---|---|---|
p.15 | 定義 | x = 3 * 8 | let x = 3 * 8 |
p.26 | 文字に対応する整数値を与える関数 | ord | ord でよいが、ghci では import Data.Char が必要。 |
p.27 | 文字列のデータのリスト[Char]の出力表記("program")の場合 | program | "program" |
最初に ord を使うと次のエラーが出る。
Prelude> ord '9' - ord '0' <interactive>:11:1: Not in scope: `ord' Perhaps you meant one of these: `odd' (imported from Prelude), `or' (imported from Prelude)
では :module Char を入れるとどうなるか
Prelude> :module Char <no location info>: Could not find module `Char' It is a member of the hidden package `haskell98-2.0.0.2'.
どうもだめなようだ。そのため、import 文を使う。
Prelude> import Data.Char Prelude Data.char> Prelude Data.char> ord '9' - ord '0' 9
まりんきょ学問所 > 関数型言語手習い > 関数型言語 Gofer