list - How to change a part of values in a record? -


i have defined type that:

type s_program =     { globals : s_var list;       main: s_block; } , s_var =     { s_var_name: string;       s_var_type: s_type;       s_var_uniqueid: s_uniqueid } , s_uniqueid = int 

at point of program, have variable p: s_program, need change s_var_uniqueid of every element of p.globals, instance, add 1 every s_var_uniqueid. have questions:

1) may modify directly related values in p, or have assign new values new p':s_program

2) may write that:

let p' =    { p       globals = list.map (fun var -> { var s_var_uniqueid = var.s_var_uniqueid + 1 }) p.globals 

thank much.

edit 1: correct with part suggested

1) depends whether want use ocaml imperative or functional programming language :). if it's former, can make both fields of records mutable (by adding mutable keyword before field name) , change them in place. i'd advice not , to:

2) go second approach, looks fine (except seem missing {...} second record modification.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -