12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697openCoremoduleMake_plain(V:sigtypet[@@derivingsexp_of]valequal:t->t->boolend)=structmoduleUpdate=structmoduleDiff=structtypet=V.t[@@derivingsexp_of]endtypet=Diff.tlist[@@derivingsexp_of]endtypet=V.tletupdatetd=matchdwith|[]->t|[t']->t'|_::non_empty_tail->List.last_exnnon_empty_tail;;letdiffs~from~to_=ifphys_equalfromto_||V.equalfromto_then[]else[to_]letto_diffst=[t]letof_diffsd=matchdwith|[t]->t|_::non_empty_tail->List.last_exnnon_empty_tail|[]->failwith"Invalid of_diffs input. Update.t for atomic must contain at least one element.";;endmoduleMake(V:sigtypet[@@derivingbin_io,sexp]valequal:t->t->boolend)=structmodulePlain=Make_plain(V)moduleUpdate=structmoduleDiff=structincludePlain.Update.Diffinclude(V:sigtypet[@@derivingbin_io,sexp]endwithtypet:=t)endtypet=Diff.tlist[@@derivingbin_io,sexp]endinclude(Plain:moduletypeofstructincludePlainendwithmoduleUpdate:=Plain.Update)endlet%test_module"tests"=(modulestructmoduleT=structtypet=int[@@derivingbin_io,equal,sexp]endincludeTincludeMake(T)let%test_unit"atomic round-trip works"=Quickcheck.testInt.quickcheck_generator~shrinker:Int.quickcheck_shrinker~sexp_of:[%sexp_of:t]~f:(funt->[%test_result:t]~expect:t(of_diffs(to_diffst)));;let%test_unit"atomic diff/update works"=letopenQuickcheckinQuickcheck.test(Generator.tuple2Int.quickcheck_generatorInt.quickcheck_generator)~shrinker:(Shrinker.tuple2Int.quickcheck_shrinkerInt.quickcheck_shrinker)~sexp_of:[%sexp_of:t*t]~f:(fun(from,to_)->[%test_result:t]~expect:to_(updatefrom(diffs~from~to_)));;end);;