+\begin{code}
+mkInstSpecEnv :: Class -- class
+ -> UniType -- instance type
+ -> [TyVarTemplate] -- instance tyvars
+ -> ThetaType -- superclasses dicts
+ -> SpecEnv -- specenv for dfun of instance
+
+mkInstSpecEnv clas inst_ty inst_tvs inst_theta
+ = mkSpecEnv (catMaybes (map maybe_spec_info matches))
+ where
+ matches = matchMEnv matchTy (getClassInstEnv clas) inst_ty
+
+ maybe_spec_info (_, match_info, MkInstTemplate dfun _ [])
+ = Just (SpecInfo (map (assocMaybe match_info) inst_tvs) (length inst_theta) dfun)
+ maybe_spec_info (_, match_info, _)
+ = Nothing
+
+\end{code}
+