123456789101112131415161718192021222324252627282930type'astate=|Unset|Setof'atype'at={mutablestate:'astate;to_dyn:'a->Dyn.t}letcreateto_dyn={state=Unset;to_dyn}letsettnew_=matcht.statewith|Unset->t.state<-Setnew_|Setold->Code_error.raise"Fdecl.set: already set"[("old",t.to_dynold);("new_",t.to_dynnew_)]letset_idempotent~equaltnew_=matcht.statewith|Unset->t.state<-Setnew_|Setold->ifnot(equalnew_old)thenCode_error.raise"Fdecl.set_idempotent: already set to a different value"[("old",t.to_dynold);("new_",t.to_dynnew_)]letgett=matcht.statewith|Unset->Code_error.raise"Fdecl.get: not set"[]|Setx->x