123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120openUtils.ResultMonadopenOdoc_modellethandle_expansionenvidexpansion=lethandle_argumentparentarg_optexprenv=(* If there's an argument, extend the environment with the argument, then
do the substitution on the signature to replace the local identifier with
the global one *)matcharg_optwith|Component.FunctorParameter.Unit->(env,expr)|Namedarg->letidentifier=Paths.Identifier.Mk.parameter(parent,Ident.Name.typed_functor_parameterarg.Component.FunctorParameter.id)inletm=Component.module_of_functor_argumentarginletenv'=Env.add_moduleidentifier(Component.Delayed.put_valm)m.docenvinletrp=`Gpath(`Identifieridentifier)inletp=`Resolvedrpinletsubst=Subst.add_module(arg.id:>Ident.path_module)prpSubst.identityinletsubst=Subst.mto_invalidate_module(arg.id:>Ident.path_module)substin(env',Subst.module_type_exprsubstexpr)inletrecexpandidenvexpansion:(Env.t*Component.ModuleType.simple_expansion,_)Result.result=matchexpansionwith|Tools.Signaturesg->Ok(env,(Component.ModuleType.Signaturesg:Component.ModuleType.simple_expansion))|Functor(arg,expr)->letenv',expr'=handle_argumentidargexprenvinTools.expansion_of_module_type_expr~mark_substituted:falseenv'expr'>>=funres->expand(Paths.Identifier.Mk.resultid)envres>>=fun(env,res)->Ok(env,(Component.ModuleType.Functor(arg,res):Component.ModuleType.simple_expansion))inexpandidenvexpansionexceptionClashletrectype_exprmapt=letopenLang.TypeExprinmatchtwith|Varv->(tryList.assocvmapwith_->Format.eprintf"Failed to list assoc %s\n%!"v;failwith"bah")|Any->Any|Alias(t,s)->ifList.mem_assocsmapthenraiseClashelseAlias(type_exprmapt,s)|Arrow(l,t1,t2)->Arrow(l,type_exprmapt1,type_exprmapt2)|Tuplets->Tuple(List.map(type_exprmap)ts)|Constr(p,ts)->Constr(p,List.map(type_exprmap)ts)|Polymorphic_variantpv->Polymorphic_variant(polymorphic_variantmappv)|Objecto->Object(object_mapo)|Class(path,ts)->Class(path,List.map(type_exprmap)ts)|Poly(s,t)->Poly(s,type_exprmapt)|Packagep->Package(packagemapp)andpolymorphic_variantmappv=letopenLang.TypeExpr.Polymorphic_variantinletconstructorc={cwithConstructor.arguments=List.map(type_exprmap)c.Constructor.arguments;}inletelement=function|Typet->Type(type_exprmapt)|Constructorc->Constructor(constructorc)in{kind=pv.kind;elements=List.mapelementpv.elements}andobject_mapo=letopenLang.TypeExpr.Objectinletmethod_m={mwithtype_=type_exprmapm.type_}inletfield=function|Methodm->Method(method_m)|Inheritt->Inherit(type_exprmapt)in{owithfields=List.mapfieldo.fields}andpackagemapp=letopenLang.TypeExpr.Packageinletsubst(frag,t)=(frag,type_exprmapt)in{pwithsubstitutions=List.mapsubstp.substitutions}letcollapse_eqnseqn1eqn2params=letopenLang.TypeDeclinletmap=List.map2(funvp->matchv.descwithVarx->Some(x,p)|Any->None)eqn2.Equation.paramsparamsinletmap=List.fold_right(funxxs->matchxwithSomex->x::xs|None->xs)map[]in{eqn1withEquation.manifest=(matcheqn2.manifestwith|None->None|Somet->Some(type_exprmapt));}