2008-03-16から1日間の記事一覧

無限数列

整数の無限数列のジェネレータみたいなもの。 # type intseq= Cons of int * (int -> intseq);; type intseq = Cons of int * (int -> intseq) フィボナッチ数列のジェネレータ # let fib = let rec f x y = Cons (x, f (x+y)) in Cons (1, f 1);; 実際に計…

足し算・かけ算からなる数式を表す型

まずは型の定義。 # type arith = Const of int | Add of arith * arith | Mul of arith * arith;; type arith = Const of int | Add of arith * arith | Mul of arith * arith 式を評価する関数・文字列に変換する関数・展開する関数 # let rec eval = func…

久々OCaml

引き続き練習問題。 # type token = PCDATA of string | Open of string | Close of string;; type token = PCDATA of string | Open of string | Close of string # type ('a, 'b) xml = XLf of 'b option | XBr of 'a * ('a, 'b) xml list;; type ('a, 'b)…