+ (clas, inst_tys) = case splitDictTy_maybe dict_ty of
+ Just ct -> ct
+ Nothing -> pprPanic "tcInstDecl1" (ppr poly_ty)
+ in
+
+ (case maybe_dfun_name of
+ Nothing -> -- A source-file instance declaration
+
+ -- Check for respectable instance type, and context
+ -- but only do this for non-imported instance decls.
+ -- Imported ones should have been checked already, and may indeed
+ -- contain something illegal in normal Haskell, notably
+ -- instance CCallable [Char]
+ scrutiniseInstanceHead clas inst_tys `thenNF_Tc_`
+ mapNF_Tc scrutiniseInstanceConstraint theta `thenNF_Tc_`
+
+ -- Make the dfun id and return it
+ newDFunName mod clas inst_tys src_loc `thenNF_Tc` \ dfun_name ->
+ returnNF_Tc (True, mkDictFunId dfun_name clas tyvars inst_tys theta)
+
+ Just dfun_name -> -- An interface-file instance declaration
+ -- Make the dfun id
+ returnNF_Tc (False, mkDictFunId dfun_name clas tyvars inst_tys theta)
+ ) `thenNF_Tc` \ (is_local, dfun_id) ->
+
+ returnTc [InstInfo { iLocal = is_local,
+ iClass = clas, iTyVars = tyvars, iTys = inst_tys,
+ iTheta = theta, iDFunId = dfun_id,
+ iBinds = binds, iLoc = src_loc, iPrags = uprags }]
+\end{code}
+
+
+%************************************************************************
+%* *
+\subsection{Extracting generic instance declaration from class declarations}
+%* *
+%************************************************************************
+
+@getGenericInstances@ extracts the generic instance declarations from a class
+declaration. For exmaple
+
+ class C a where
+ op :: a -> a
+
+ op{ x+y } (Inl v) = ...
+ op{ x+y } (Inr v) = ...
+ op{ x*y } (v :*: w) = ...
+ op{ 1 } Unit = ...
+
+gives rise to the instance declarations
+
+ instance C (x+y) where
+ op (Inl v) = ...
+ op (Inr v) = ...
+
+ instance C (x*y) where
+ op (v :*: w) = ...
+
+ instance C 1 where
+ op Unit = ...
+
+
+\begin{code}
+getGenericInstances :: Module -> [RenamedTyClDecl] -> TcM [InstInfo]
+getGenericInstances mod class_decls
+ = mapTc (get_generics mod) class_decls `thenTc` \ gen_inst_infos ->
+ let
+ gen_inst_info = concat gen_inst_infos