に期待演算子、文字4-7 (ここではコードを参照:http://pastebin.com/VxCM5cAV):OCAML:私はライン183上の「期待演算子」を取得しておく機能
は、これらは私が最近追加された線であり、
let rec sem ((e: exp), (r: eval env)) =
[...]
| Apply(Pipe tup, eArg) -> unrollPipe tup sem(eArg, r) r
[...]
and rec unrollPipe tup evarg r = match tup with
| Seq(Den f, ttup) ->
let fclosure= sem(Den f, r) in
match fclosure with
| Funval(arg, fbody, fDecEnv) ->
let fres = sem(fbody, bind(fDecEnv, arg, evarg)) in
unrollPipe Pipe(ttup) fres r
| RecFunVal(f, arg, fbody, fDecEnv) ->
let rEnv= bind(fDecEnv, f, fclosure) in
let aEnv= bind(rEnv, arg, evarg) in
let fres = sem(fbody, aEnv) in
unrollPipe Pipe(ttup) fres r
| Seq(Pipe(ftup), ttup) ->
let fres = unrollPipe Pipe(ftup) evarg r in
unrollPipe Pipe(ttup) fres r
| Nil -> evarg
| _ -> failwith("bad Pipe")
;;
SEM((EXP * evalのENV) - > evalの)あるべき機能
このコードの目的は、あなたが機能(Funvalの配列からなるパイプを適用できますインタプリタを実装することで、 RecFunValはどちらも "Ide f"または別のPとして与えられます(パイプ(tup)、eArg)の各出現を取って、そのパラメータをevalに評価し、次に進むことによって、パラメータを表現する与えられた式に変換することができます(単なる単なる関数と考える)
UnrollPipe(fun:tuple * eval - > eval)を使用して、前に評価したパラメータにパイプの最初の関数を適用し、パイプの末尾と前の関数の結果を再帰的に呼び出すこれは、パイプ内のすべての機能の構成を計算することにつながります。私はこのコードで使用
の種類は次のとおりです。
EXP:
type ide = string
type exp =
| Eint of int
| Ebool of bool
| Den of ide
| Sum of exp * exp
| Diff of exp * exp
| Prod of exp * exp
| Eq of exp * exp
| Minus of exp
| Iszero of exp
| Or of exp * exp
| And of exp * exp
| Not of exp
| Ifthenelse of exp * exp * exp
| Let of ide * exp * exp(* Dichiarazione di ide: modifica ambiente*)
| Fun of ide * exp(* Astrazione di funzione*)
| Apply of exp * exp (* Applicazione di funzione*)
| Letrec of ide(*nome fun*)*ide(*par.formale*)*exp(*body fun*)*exp(*body let*)
| Etup of tuple (*Tupla come espressione*)
| Pipe of tuple (*Concatenazione di funzioni*)
| ManyTimes of int * exp (*Esecuzione iterata di una funzione*)
and tuple =
| Nil (*Tupla vuota*)
| Seq of exp * tuple (*Tupla di espressioni*)
;;
とのeval:
type eval=
| Int of int
| Bool of bool
| Unbound
| RecFunVal of ide * ide * exp * eval env
| Funval of efun
| ValTup of evtuple
and efun = ide* exp * eval env
and evtuple =
| Nil
| Seq of eval * evtuple
;;
編集:私は、固定され、大文字で機能を命名しましたそれでは、183行目に新しい「構文エラー」があります。文字4-7 もペーストビンを更新しました(http://pastebin.com/VxCM5cAV)
これは反復的にunrollPipeと呼ばれるtupの代わりにパラメータとしてパイプ(tup) – NokiStrawby