今日のOCaml RSS

Type-safe Unmarshalling for Objective Caml

http://www.pps.jussieu.fr/~henry/marshal/index.en.html

This type-safe unmarshalling does not need any modification of the OCaml runtime, and in particular uses the current format of marshalled values. The unmarshalling function is correctly typed thanks to an extra argument that represents the expected type of the value to be read. The dynamic compatibility check of the value against the type is performed by going through the whole value, interpreting cycles and sharing as polymorphic type constraints.

どこかで見たような GCaml みたいな物。Runtime は変更しないがコンパイラは改造するのは GCaml と一緒。違いは GCaml では serialize した値を型情報と一緒に書き込んでおいて、読み込み時には型を検査することで安全性を担保していたが、この実装では読み込み時に marshalled value その物を読み取り側が期待する型の値として受け入れられるかを実行時型検査する。効率は悪くなるが元と違った型になったとしても安全であれば構わない、というフレキシビリティがある。GCaml の様な type dispatching は行わないようだ。コンパイラ改造なので軽々しく使えないというのは GCaml と同じ。Sexplib の p4 がいらない marshal 版というのが一番簡単かな。んー、でもじゃあ p4 で出来るじゃん、ってウチの会社に正に Sexplib のバイナリ版があった。

OCamlRubyのパーサー

http://ocaml-nagoya.g.hatena.ne.jp/yoshihiro503/20090426

Rubyのサブセット min_ruby のパーサーをOCamlで実装してみた
http://bitbucket.org/yoshihiro503/min_ruby/
プログラムは今のところ全部で232行

OCamlRuby をいじめる、もとい、いじるのが流行っているのか。

Sudoku in ocamljs, part 1: DOM programming

http://ambassadortothecomputers.blogspot.com/2009/04/sudoku-in-ocamljs-part-1-dom.html

Let's make a Sudoku game with ocamljs and the Dom library for programming the browser DOM. Like on the cooking shows, I have prepared the dish we're about to make beforehand; why don't you taste it now? OK, it is not yet Sudoku, lacking the important ingredient of some starting numbers to guide the game--we'll come back to that next time.

ocamljs の working example がようやく出た。まだ Sudoku になってないけど、こんな感じで OCaml を書いてコンパイルしてあげれば何か出来るらしい。適当に数字入れてから Check を押すと、Sudoku の条件を満たしていないセルが赤くなる。コンパイルされたコードは、まあまあ見易い、と思う。