Version française
Home     About     Download     Resources     Contact us    

This site is updated infrequently. For up-to-date information, please visit the new OCaml website at

Browse thread
[Caml-list] "changing" immutable record elements
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Virgile Prevosto <prevosto@m...>
Subject: Re: [Caml-list] "changing" immutable record elements
Le vendredi 14 mai, à  8h50 -0700,
David Fox a écrit:

> Unless I am missing some core language feature, it seems to me that
> the most awkward part of the language is constructing an expression
> that represents a record with a single field modified:
> let set_field3 rec value =
>    match rec with
>        {field1=field1; field2=field2; field3=field3; field4=field4; 
> field5=field5} ->
>           {field1=field1; field2=field2; field3=value; field4=field4; 
> field5=field5}
> is there any prettier way of doing this?
let set_field_3 my_rec v = {my_rec with field3=v} 
(cf, section

By the way, rec and value are keywords in ocaml. you might run
into trouble if you try to use them as identifiers ;-)

E tutto per oggi, a la prossima volta

To unsubscribe, mail Archives:
Bug reports: FAQ:
Beginner's list: