Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update single record field in Coq

I have a record type with a lot of fields:

Record r : Set :=
  R {
    field1 : nat;
    field2 : nat;
    field3 : nat;
...
    field2137 : nat;
  }

I would like to have a function that will update just one field in this record. In Haskell I would do it like this

update2019 record x = record {field2019 = x}

How can I perform such an action in Coq?

like image 327
radrow Avatar asked Oct 26 '25 10:10

radrow


1 Answers

Unfortunately, Coq lacks support for record update. Luckily for us, there is coq-record-update library by @tchajed that greatly simplifies this. Here is an example:

From RecordUpdate Require Import RecordSet.
Import RecordSetNotations.

Record r : Set :=
  R {
    f1 : nat;
    f2 : nat;
    f3 : nat;
  }.
Instance eta_r : Settable _ := settable! R <f1; f2; f3>.

Definition update3 record x : r := record <| f3 := x |>.

Please see the library's README.md file for more detail.

like image 78
Anton Trunov Avatar answered Oct 29 '25 09:10

Anton Trunov