moduleDDC.Core.Check.CheckModule(checkModule,checkModuleM)whereimportDDC.Core.ModuleimportDDC.Core.ExpimportDDC.Core.Check.CheckExpimportDDC.Core.Check.ErrorimportDDC.Type.CompoundsimportDDC.Base.PrettyimportDDC.Type.EquivimportDDC.Type.Env(KindEnv,TypeEnv)importDDC.Control.Monad.Check(result,throw)importData.Map(Map)importqualifiedDDC.Type.CheckasTimportqualifiedDDC.Type.EnvasEnvimportqualifiedData.MapasMap-- Wrappers --------------------------------------------------------------------- | Type check a module.---- If it's good, you get a new version with types attached to all the bound-- variables---- If it's bad, you get a description of the error.checkModule::(Ordn,Shown,Prettyn)=>Confign-- ^ Static configuration.->Modulean-- ^ Module to check.->Either(Erroran)(Module(AnTECan)n)checkModule!config!xx=result$checkModuleMconfig(configPrimKindsconfig)(configPrimTypesconfig)xx-- checkModule ------------------------------------------------------------------ | Like `checkModule` but using the `CheckM` monad to handle errors.checkModuleM::(Ordn,Shown,Prettyn)=>Confign-- ^ Static configuration.->KindEnvn-- ^ Starting kind environment.->TypeEnvn-- ^ Starting type environment.->Modulean-- ^ Module to check.->CheckMan(Module(AnTECan)n)checkModuleM!config!kenv!tenvmm@ModuleCore{}=do-- Convert the imported kind and type map to a list of binds.letbksImport=[BNamenk|(n,(_,k))<-Map.toList$moduleImportKindsmm]letbtsImport=[BNament|(n,(_,t))<-Map.toList$moduleImportTypesmm]-- Check the imported kinds and types.-- The imported types are in scope in both imported and exported signatures.mapM_(checkTypeMconfigkenv)$maptypeOfBindbksImportletkenv'=Env.unionkenv$Env.fromListbksImportmapM_(checkTypeMconfigkenv')$maptypeOfBindbtsImportlettenv'=Env.uniontenv$Env.fromListbtsImport-- Check the sigs for exported things.mapM_(checkTypeMconfigkenv')$Map.elems$moduleExportKindsmmmapM_(checkTypeMconfigkenv')$Map.elems$moduleExportTypesmm-- Check our let bindings.(x',_,_effs,_)<-checkExpMconfigkenv'tenv'(moduleBodymm)-- Check that each exported signature matches the type of its binding.envDef<-checkModuleBinds(moduleExportKindsmm)(moduleExportTypesmm)x'-- Check that all exported bindings are defined by the module.mapM_(checkBindDefinedenvDef)$Map.keys$moduleExportTypesmm-- Return the checked bindings as they have explicit type annotations.letmm'=mm{moduleBody=x'}returnmm'-- | Check that the exported signatures match the types of their bindings.checkModuleBinds::Ordn=>Mapn(Kindn)-- ^ Kinds of exported types.->Mapn(Typen)-- ^ Types of exported values.->Exp(AnTECan)n->CheckMan(TypeEnvn)-- ^ Environment of top-level bindings-- defined by the modulecheckModuleBinds!ksExports!tsExports!xx=casexxofXLet_(LLetb_)x2->docheckModuleBindksExportstsExportsbenv<-checkModuleBindsksExportstsExportsx2return$Env.extendbenvXLet_(LRecbxs)x2->domapM_(checkModuleBindksExportstsExports)$mapfstbxsenv<-checkModuleBindsksExportstsExportsx2return$Env.extends(mapfstbxs)envXLet_(LLetRegions__)x2->checkModuleBindsksExportstsExportsx2_->returnEnv.empty-- | If some bind is exported, then check that it matches the exported version.checkModuleBind::Ordn=>Mapn(Kindn)-- ^ Kinds of exported types.->Mapn(Typen)-- ^ Types of exported values.->Bindn->CheckMan()checkModuleBind!_ksExports!tsExports!b|BNamentDef<-b=caseMap.lookupntsExportsofNothing->return()JusttExport|equivTtDeftExport->return()|otherwise->throw$ErrorExportMismatchntExporttDef-- Only named bindings can be exported, -- so we don't need to worry about non-named ones.|otherwise=return()-- | Check that a top-level binding is actually defined by the module.checkBindDefined::Ordn=>TypeEnvn-- ^ Types defined by the module.->n-- ^ Name of an exported binding.->CheckMan()checkBindDefinedenvn=caseEnv.lookup(UNamen)envofJust_->return()_->throw$ErrorExportUndefinedn--------------------------------------------------------------------------------- | Check a type in the exp checking monad.checkTypeM::(Ordn,Shown,Prettyn)=>Confign->KindEnvn->Typen->CheckMan(Kindn)checkTypeM!config!kenv!tt=caseT.checkTypeconfigkenvttofLefterr->throw$ErrorTypeerrRightk->returnk