- = tc_mb_pats mbinds `thenTc` \ (complete_it, lie_req_pat, tvs, ids, lie_avail) ->
- let
- id_list = bagToList ids
- (names, mono_ids) = unzip id_list
-
- -- This last defn is the key one:
- -- extend the val envt with bindings for the
- -- things bound in this group, overriding the monomorphic
- -- ids with the polymorphic ones from the pattern
- extra_val_env = case is_rec of
- Recursive -> map mk_bind id_list
- NonRecursive -> []
- in
- -- Don't know how to deal with pattern-bound existentials yet
- checkTc (isEmptyBag tvs && isEmptyBag lie_avail)
- (existentialExplode mbinds) `thenTc_`
-
- -- *Before* checking the RHSs, but *after* checking *all* the patterns,
- -- extend the envt with bindings for all the bound ids;
- -- and *then* override with the polymorphic Ids from the signatures
- -- That is the whole point of the "complete_it" stuff.
- --
- -- There's a further wrinkle: we have to delay extending the environment
- -- until after we've dealt with any pattern-bound signature type variables
- -- Consider f (x::a) = ...f...
- -- We're going to check that a isn't unified with anything in the envt,
- -- so f itself had better not be! So we pass the envt binding f into
- -- complete_it, which extends the actual envt in TcMatches.tcMatch, after
- -- dealing with the signature tyvars
-
- complete_it extra_val_env `thenTc` \ (mbinds', lie_req_rhss) ->
-
- returnTc (mbinds', lie_req_pat `plusLIE` lie_req_rhss, names, mono_ids)
+ -- Three stages:
+ -- 1. Check the patterns, building up an environment binding
+ -- the variables in this group (in the recursive case)
+ -- 2. Extend the environment
+ -- 3. Check the RHSs
+ = tc_mb_pats mbinds `thenM` \ (complete_it, xve) ->
+ tcExtendLocalValEnv2 (bagToList xve) complete_it