diff --git a/content/mimiumの多段階計算.md b/content/mimiumの多段階計算.md index 22b07d8a..f1349a60 100644 --- a/content/mimiumの多段階計算.md +++ b/content/mimiumの多段階計算.md @@ -186,5 +186,49 @@ persistentである時点でcode型が現れないかのチェックをする必 単なる置き換えだと、includeしたファイルの定義によってその下のステージが変わってしまう可能性がある? +--- + +[[OCaml]]で書いてみてる + +```ocaml +type expr = NumLit of float + | Var of string + | App of expr * expr + | Lam of string * expr + | Delay of int * expr * expr + | Feed of string * expr + | Quote of expr + | Splice of expr + | Tuple of expr list + | Proj of expr * int +type bound = string * value +and env = bound list +and value = Real of float + | OpenFn of string * expr * int + | Closure of string * expr * env + | Code of expr +type state = float list +type stage = int +type stateptr = int + +let lookup: string->env->value = + fun name env -> let finder = fun (n,v) -> n == name in + let (_n,v) = List.find finder env in + v + + + +let rec contain_freevars: string -> expr -> env -> bool = + ... + + +let rec eval : stage -> expr -> env ->value = + fun stage e env -> match e with + | NumLit(n) -> Real(n) + | Var(name)-> lookup name env + | + |_ -> raise (Failure "not implemented yet") + +```