Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file ctxt.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172(** Typing context. *)openTermopenLplibopenExtraopenTimedopenCommonopenName(** [type_of x ctx] returns the type of [x] in the context [ctx] when it
appears in it, and @raise [Not_found] otherwise. *)lettype_of:var->ctxt->term=funxctx->let(_,a,_)=List.find(fun(y,_,_)->eq_varsxy)ctxina(** [def_of x ctx] returns the definition of [x] in the context [ctx] if it
appears, and [None] otherwise *)letrecdef_of:var->ctxt->ctxt*termoption=funxc->matchcwith|[]->[],None|(y,_,d)::c->ifeq_varsxythenc,delsedef_ofxc(** [to_prod ctx t] builds a product by abstracting over the context [ctx], in
the term [t]. It returns the number of products as well. *)letto_prod:ctxt->term->term*int=functxt->letf(t,k)(x,a,d)=letb=bind_varxtinletu=matchdwith|None->mk_Prod(a,b)|Somed->mk_LLet(a,d,b)inu,k+1inList.fold_leftf(t,0)ctx(** [unfold ctx t] behaves like {!val:Term.unfold} unless term [t] is of the
form [Vari(x)] with [x] defined in [ctx]. In this case, [t] is replaced by
the definition of [x] in [ctx]. In particular, if no operation is carried
out on [t], we have [unfold ctx t == t]. *)letrecunfold:ctxt->term->term=functxt->matchtwith|Meta(m,ts)->beginmatch!(m.meta_value)with|None->t|Some(b)->unfoldctx(msubstbts)end|TRef(r)->beginmatch!rwith|None->t|Some(v)->unfoldctxvend|Vari(x)->beginmatchdef_ofxctxwith|_,None->t|ctx',Somet->unfoldctx'tend|_->t(** [to_map] builds a map from a context. *)letto_map:ctxt->termVarMap.t=letadd_defm(x,_,v)=matchvwithSomev->VarMap.addxvm|None->minList.fold_leftadd_defVarMap.empty(** [names c] returns the set of names in [c]. *)letnames:ctxt->intStrMap.t=letadd_declidmap(v,_,_)=add_name(base_namev)idmapinList.fold_leftadd_declStrMap.empty(** [fresh c id] returns a string starting with [id] and not in [c]. *)letfresh(c:ctxt)(id:string):string=fst(get_safe_prefixid(namesc))