Copying fields in OCaml

I have a very simple question regarding OCaml entries. Suppose I have an entry:

type r = {a:int;b:int;c:int} let x = {a=3;b=8;c=2} 

Now suppose I want to create a new record that has all fields equal to x but having c = 4. I could write:

 let y = {a=3;b=8;c=4} 

but this is annoying because there is no need to rewrite a = 3 and b = 8. I could also write:

 let y = {a=xa;b=xb;c=4} 

but it’s still not very good if there are many fields in the record. Is there a way to write something like:

 let y = {x with c=4} 

or something like that?

Thanks so much for any help.

All the best, Surikator.

+7
syntax field ocaml records
source share
1 answer

yes, and what is the exact syntax.

 let y = {x with c=4} 
+15
source share

All Articles