OCamlメモ
- INRIA OCAML本家
- Documentation and user’s manual
- OCamlJP
- camlcity.org
- OCamlCore.org
- syntax in OCaml Cheatsheet
- OCaml Cheat Sheets by OCamlPro
- ObjectiveCaml入門(pdf) by 五十嵐淳さん
- Developing Applications With Objective Caml(和訳)(pdf) 原著
- OCaml備忘録
- http://www002.upp.so-net.ne.jp/mamewo/ml.html
- OMake
- OCamlForge
- 有用なライブラリが沢山
- OCamlBatteriesのBatRopeモジュールで使われる rope というデータ構造が面白い。stringsの代替。
- lablgtk-react
- Lablgtk2-react interfaces lablgtk2 properties and signals with Functional Reactive Programming (FRP) libraries like React.
- OSXへOCamlの開発環境構築し直した
- rlwrap
alias ocaml='rlwrap -H ~/.ocaml_history -D 2 -i -s 10000 ocaml'
- 数理科学的バグ撲滅方法論のすすめ by 住井さん
- η展開 (eta expansion)
- 末尾呼出(tail-call)最適化
- α変換、β変換、α同値
- K正規化、A正規化、CPS変換
- マシン語までの変換のために抽象度を落とすために必要となってくる変換
- K正規化
x + y + z
を
t0 = x + y t1 = t + z
みたいなかんじに
- findlib
- インストールするとREPLの拡張やocamlfindコマンドの追加が行われる
- ocamlfind の引数にコンパイルコマンド(ocamlc|ocamlopt 〜)を与えるとリンクするライブラリをいちいち列挙せずにすむ
- 高速化用オプション 参考1 参考2
ocamlopt -unsafe -ccopt -O9 -noassert -inline<n> -ffast-math
- Coq は dependent type を持ったプログラミング言語, OCamlで実装されている, 証明されたOCamlのコード生成も可能?
- js_of_ocaml http://ocsigen.org/js_of_ocaml/
- OCamlで fastInvSqrt
let fastInvSqrt x = let xhalf = 0.5 *. x in let i = Int32.bits_of_float x in let t = Int32.sub 0x5f3759dfl (Int32.shift_right_logical i 1) in let r = Int32.float_of_bits t in r *. (1.5 -. xhalf *. r *. r);;
fun x -> x |> float |> sqrt |> Float.to_int
は
fun x -> Float.to_int (sqrt (float x))
と等価
let rec fact n = if n = 1 then 1 else n * (fact (n-1))
はOK
let rec x = x let rec x = 1 + x
はNG
違いは定義しようとしている変数が他の関数に適用されるかどうか。
- OCaml 標準ライブラリ探訪 #0 - Oh, you `re no (fun _ → more)
- int が 32bits なのは unboxed int なのか pointer なのかを区別するため
- lablgtk2
- REPLの場合 ocaml -I +lablgtk2 として
#load "gtkInit.cmo";;
-
- とすれば動く ocamlc の場合 gtkInit.cmx をリンクする必要がある
ocamlfind ocamlopt -package lablgtk2 -linkpkg gtkInit.cmx test_gtk.ml -o test_gtk
Batteries と スレッド環境でのコンパイル
ocamlfind ocamlopt -thread -package lablgtk2 -package batteries -linkpkg gtkInit.cmx test_gtk.ml -o test_gtk
- ContinuationPassingStyle in OCaml
# let id x = x # let rec fact n c = if n < 2 then c 1 else fact (n-1) (fun x -> c (n * x));; # let rec fib n c = if n < 2 then c 1 else fib (n-1) (fun x -> c (x + fib (n-2) id))