School of Expression

The Haskell School of Expression (通称 SOE) という書籍を大購入して読み中。なかなか楽しい。

http://www.haskell.org/soe/software1.htm にて SOEGraphics (旧称) モジュールの最新版が配布されている。インストラクションにしたがって 6.8.2 Haskell を導入し GLFW を環境に追加し SOE のソースを GHCi で実行してみる…。

うわ、 Animation とかちゃんと動くよ!

> cd SOE-20071003\SOE\src
> ghci Animation.lhs
GHCi, version 6.8.2: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 6] Compiling Shape            ( Shape.lhs, interpreted )
[2 of 6] Compiling Region           ( Region.lhs, interpreted )
[3 of 6] Compiling SOE              ( SOE.hs, interpreted )
[4 of 6] Compiling Draw             ( Draw.lhs, interpreted )
[5 of 6] Compiling Picture          ( Picture.lhs, interpreted )
[6 of 6] Compiling Animation        ( Animation.lhs, interpreted )
Ok, modules loaded: SOE, Animation, Picture, Region, Shape, Draw.
*Animation> main2

CPU 使用率が 0 に張りついたままなんだけど、ちゃんと画面は更新されている。しかるにウィンドウはスペースキーの押下で閉じる。

ええと、キーイベントの監視とタイマーの監視の両方を見張って、適切に CPU を開放するコードは Haskell でも書けるってこと?!

…ではないみたいなんだけどなあ。ソースを読むと spaceCloseEx ってのが肝なんだけれど、イベントがなければ loop をがんがん呼び出すビジーループになっている、気がする。