section \Tests\ theory Test_BNF_Record imports BNF_Record begin subsection \Standard usage\ bnf_record ('a, 'b) foo = field_1 :: 'a field_2 :: 'b lemma "\ field_1 = 3, field_2 = () \ = (make_foo 3 () :: (nat, unit) foo)" .. lemma "(make_foo a b) \ field_1 := y \ = make_foo y b" by (simp add: bnf_record_update) lemma "(make_foo a b) \ foo.field_1 := y \ = make_foo y b" by (simp add: bnf_record_update) subsection \Existing datatypes\ datatype x = X (a: int) (b: int) lemma "\ a = 1, b = 2 \ = X 1 2" .. local_setup \BNF_Record.mk_update_defs @{type_name x}\ lemma "(X 1 2) \ b := 3 \ = X 1 3" by (simp add: bnf_record_update) subsection \Nested recursion\ bnf_record 'a container = content :: "'a option" datatype 'a contrived = Contrived "'a contrived container" term "Contrived \ content = None \" end