Quantcast
Channel: Active questions tagged ocaml - Stack Overflow
Viewing all articles
Browse latest Browse all 527

Appending elements to a map

$
0
0
let interp_fundef (d: Ast.fundef) (g: FStore.t) : FStore.t =   match d with  | Ast.FunDef (x, pl, e) -> (FStore.add x (pl, e) g)let interp (p: Ast.prog) : Value.t =   let g = FStore.empty in  let s = Store.empty in  match p with  | Ast.Prog (dl, e) ->    let _ =       let rec fdef defl =        match defl with        | [] -> ()        | h1::t1 ->           let _ = (interp_fundef h1 g) in          (fdef t1)      in fdef dl;    in interp_expr e g s

fStore.ml

module M = Map.Make(String)type t = (string list * Ast.expr) M.tlet add = M.addlet mem = M.memlet find = M.findlet empty = M.empty

ast.ml

type fundef = FunDef of string * string list * exprtype prog = Prog of fundef list * expr

I'm making an f1vae interpreter in OCaml.In the above code, I intended to make an fstore map which is storing all fundef,before interpreting the expression in prog.

How can I append fundef to g one by one?I want the interp_fundef to be unchanged.


Viewing all articles
Browse latest Browse all 527

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>