-tcCheckMainSig mod_name
- | mod_name /= mAIN
- = returnTc () -- A non-main module
-
- | otherwise
- = -- Check that main is defined
- tcLookupTyCon ioTyCon_NAME `thenTc` \ (_,_,ioTyCon) ->
- tcLookupLocalValue main_NAME `thenNF_Tc` \ maybe_main_id ->
- case maybe_main_id of {
- Nothing -> failTc noMainErr;
- Just main_id ->
-
- -- Check that it has the right type (or a more general one)
- let expected_ty = applyTyCon ioTyCon [unitTy] in
- tcInstType [] expected_ty `thenNF_Tc` \ expected_tau ->
- tcId main_NAME `thenNF_Tc` \ (_, lie, main_tau) ->
- tcSetErrCtxt mainTyCheckCtxt $
- unifyTauTy expected_tau
- main_tau `thenTc_`
- checkTc (isEmptyBag lie) (mainTyMisMatch expected_ty (idType main_id))
- }
-
-mainTyCheckCtxt sty
- = hsep [ptext SLIT("When checking that"), ppr sty main_NAME,
- ptext SLIT("has the required type")]
-
-noMainErr sty
- = hsep [ptext SLIT("Module"), pprModule sty mAIN,
- ptext SLIT("must include a definition for"), ppr sty main_NAME]
-
-mainTyMisMatch :: Type -> TcType s -> Error
-mainTyMisMatch expected actual sty
- = hang (hsep [ppr sty main_NAME, ptext SLIT("has the wrong type")])
- 4 (vcat [
- hsep [ptext SLIT("Expected:"), ppr sty expected],
- hsep [ptext SLIT("Inferred:"), ppr sty actual]
- ])