関数型言語 Gofer

作成日:2008-04-14
最終更新日:

関数型言語 Gofer

Gofer は、Haskell の教育用言語、と Wikipedia (英語版)には書かれている。また、名称の由来は "Good For Equational Reasoning" として同じく Wikipedia に解説されている。 わたしが持っている Gofer の本は、 武市正人先生の「プログラミング言語」(以下、本と称する)だけである。

インストール

上述の通り、Gofer をインストールするというより、 Haskell の処理系 ghc や ghci で、 「プログラミング言語」の例を検証しようと思う。

言語プログラミングの言語

以下、本の第2章を追う。

Gofer と Haskell の違い

ページ内容GoferHaskell
p.15 定義 x = 3 * 8 let x = 3 * 8
p.26 文字に対応する整数値を与える関数 ordord でよいが、ghci では import Data.Char が必要。
p.27 文字列のデータのリスト[Char]の出力表記("program")の場合 program"program"

関数 ord

最初に 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


MARUYAMA Satosi