- -> [Name] -> [TcIdBndr s]
- -> [TcSigInfo s]
- -> TcM s (TcMonoBinds s, LIE s)
-
-tcMonoBinds mbind binder_names mono_ids tc_ty_sigs
- = tcExtendLocalValEnv binder_names mono_ids (
- tc_mono_binds mbind
- )
- where
- sig_names = [name | (TySigInfo name _ _ _ _ _) <- tc_ty_sigs]
- sig_ids = [id | (TySigInfo _ id _ _ _ _) <- tc_ty_sigs]
-
- tc_mono_binds EmptyMonoBinds = returnTc (EmptyMonoBinds, emptyLIE)
-
- tc_mono_binds (AndMonoBinds mb1 mb2)
- = tc_mono_binds mb1 `thenTc` \ (mb1a, lie1) ->
- tc_mono_binds mb2 `thenTc` \ (mb2a, lie2) ->
- returnTc (AndMonoBinds mb1a mb2a, lie1 `plusLIE` lie2)
-
- tc_mono_binds (FunMonoBind name inf matches locn)
- = tcAddSrcLoc locn $
- tcLookupLocalValueOK "tc_mono_binds" name `thenNF_Tc` \ id ->
-
- -- Before checking the RHS, extend the envt with
- -- bindings for the *polymorphic* Ids from any type signatures
- tcExtendLocalValEnv sig_names sig_ids $
- tcMatchesFun name (idType id) matches `thenTc` \ (matches', lie) ->
-
- returnTc (FunMonoBind (TcId id) inf matches' locn, lie)
-
- tc_mono_binds bind@(PatMonoBind pat grhss_and_binds locn)
- = tcAddSrcLoc locn $
- tcPat pat `thenTc` \ (pat2, lie_pat, pat_ty) ->
- tcExtendLocalValEnv sig_names sig_ids $
- tcGRHSsAndBinds grhss_and_binds `thenTc` \ (grhss_and_binds2, lie, grhss_ty) ->
- tcAddErrCtxt (patMonoBindsCtxt bind) $
- unifyTauTy pat_ty grhss_ty `thenTc_`
- returnTc (PatMonoBind pat2 grhss_and_binds2 locn,
- plusLIE lie_pat lie)
-\end{code}
-
-%************************************************************************
-%* *
-\subsection{Signatures}
-%* *
-%************************************************************************
-
-@tcSigs@ checks the signatures for validity, and returns a list of
-{\em freshly-instantiated} signatures. That is, the types are already
-split up, and have fresh type variables installed. All non-type-signature
-"RenamedSigs" are ignored.
-
-The @TcSigInfo@ contains @TcTypes@ because they are unified with
-the variable's type, and after that checked to see whether they've
-been instantiated.
-
-\begin{code}
-data TcSigInfo s
- = TySigInfo Name
- (TcIdBndr s) -- *Polymorphic* binder for this value...
- [TcTyVar s] (TcThetaType s) (TcTauType s)
- SrcLoc
-\end{code}
-
-
-\begin{code}
-tcTySig :: RenamedSig -> TcM s (TcSigInfo s)
-
-tcTySig (Sig v ty src_loc)
- = tcAddSrcLoc src_loc $
- tcHsType ty `thenTc` \ sigma_ty ->
- tcGetUnique `thenNF_Tc` \ uniq ->
- tcInstSigType sigma_ty `thenNF_Tc` \ sigma_ty' ->
- let
- poly_id = mkUserLocal (getOccName v) uniq sigma_ty' src_loc
- (tyvars', theta', tau') = splitSigmaTy sigma_ty'
- in
- returnTc (TySigInfo v poly_id tyvars' theta' tau' src_loc)
-\end{code}
-
-@checkSigMatch@ does the next step in checking signature matching.
-The tau-type part has already been unified. What we do here is to
-check that this unification has not over-constrained the (polymorphic)
-type variables of the original signature type.
-
-The error message here is somewhat unsatisfactory, but it'll do for
-now (ToDo).
-
-\begin{code}
-checkSigMatch binder_names_w_mono_isd []
- = returnTc (error "checkSigMatch")
-
-checkSigMatch binder_names_w_mono_ids tc_ty_sigs
- =
-
- -- CHECK THAT THE SIGNATURE TYVARS AND TAU_TYPES ARE OK
- -- Doesn't affect substitution
- mapTc check_one_sig tc_ty_sigs `thenTc_`
-
- -- CHECK THAT ALL THE SIGNATURE CONTEXTS ARE IDENTICAL
- -- The type signatures on a mutually-recursive group of definitions
- -- must all have the same context (or none).
- -- We have to zonk them first to make their type variables line up
- mapNF_Tc get_zonked_theta tc_ty_sigs `thenNF_Tc` \ (theta:thetas) ->
- checkTc (all (eqSimpleTheta theta) thetas)
- (sigContextsErr tc_ty_sigs) `thenTc_`
-
- returnTc theta