- -- Value declarations next.
- -- We also typecheck any extra binds that came out of the "deriving" process
- -- trace "tcBinds:" $
- tcBindsAndThen
- (\ binds1 (binds2, thing) -> (binds1 `ThenBinds` binds2, thing))
- (get_val_decls decls `ThenBinds` deriv_binds)
- ( -- Second pass over instance declarations,
- -- to compile the bindings themselves.
- -- trace "tc8" $
- tcInstDecls2 inst_info `thenNF_Tc` \ (lie_instdecls, inst_binds) ->
- tcClassDecls2 decls `thenNF_Tc` \ (lie_clasdecls, cls_binds) ->
- tcCheckMainSig mod_name `thenTc_`
- tcGetEnv `thenNF_Tc` \ env ->
- returnTc ( (EmptyBinds, (inst_binds, cls_binds, env)),
- lie_instdecls `plusLIE` lie_clasdecls
- )
- )
-
- `thenTc` \ ((val_binds, (inst_binds, cls_binds, final_env)), lie_alldecls) ->
-
- -- Deal with constant or ambiguous InstIds. How could
- -- there be ambiguous ones? They can only arise if a
- -- top-level decl falls under the monomorphism
- -- restriction, and no subsequent decl instantiates its
- -- type. (Usually, ambiguous type variables are resolved
- -- during the generalisation step.)
- -- trace "tc9" $
- tcSimplifyTop lie_alldecls `thenTc` \ const_insts ->
-
-
- -- Backsubstitution. Monomorphic top-level decls may have
- -- been instantiated by subsequent decls, and the final
- -- simplification step may have instantiated some
- -- ambiguous types. So, sadly, we need to back-substitute
- -- over the whole bunch of bindings.
- --
- -- More horrible still, we have to do it in a careful order, so that
- -- all the TcIds are in scope when we come across them.
- --
- -- These bindings ought really to be bundled together in a huge
- -- recursive group, but HsSyn doesn't have recursion among Binds, only
- -- among MonoBinds. Sigh again.
- zonkBinds nullTyVarEnv nullIdEnv (MonoBind const_insts [] nonRecursive)
- `thenNF_Tc` \ (const_insts', ve1) ->
- zonkBinds nullTyVarEnv ve1 val_binds `thenNF_Tc` \ (val_binds', ve2) ->