-
-data Foo ... = ...
-
-con2tag_Foo :: Foo ... -> Int#
-tag2con_Foo :: Int -> Foo ... -- easier if Int, not Int#
-maxtag_Foo :: Int -- ditto (NB: not unlifted)
-
-
-We have a @con2tag@ function for a tycon if:
-\begin{itemize}
-\item
-We're deriving @Eq@ and the tycon has nullary data constructors.
-
-\item
-Or: we're deriving @Ord@ (unless single-constructor), @Enum@, @Ix@
-(enum type only????)
-\end{itemize}
-
-We have a @tag2con@ function for a tycon if:
-\begin{itemize}
-\item
-We're deriving @Enum@, or @Ix@ (enum type only???)
-\end{itemize}
-
-If we have a @tag2con@ function, we also generate a @maxtag@ constant.
-
-\begin{code}
-genTaggeryBinds :: [(InstInfo, TyCon)] -> TcM (LHsBinds RdrName)
-genTaggeryBinds infos
- = do { names_so_far <- foldlM do_con2tag [] tycons_of_interest
- ; nm_alist_etc <- foldlM do_tag2con names_so_far tycons_of_interest
- ; return (listToBag (map gen_tag_n_con_monobind nm_alist_etc)) }
- where
- all_CTs = [ (fst (simpleInstInfoClsTy info), tc)
- | (info, tc) <- infos]
- all_tycons = map snd all_CTs
- (tycons_of_interest, _) = removeDups compare all_tycons
-
- do_con2tag acc_Names tycon
- | isDataTyCon tycon &&
- ((we_are_deriving eqClassKey tycon
- && any isNullarySrcDataCon (tyConDataCons tycon))
- || (we_are_deriving ordClassKey tycon
- && not (isProductTyCon tycon))
- || (we_are_deriving enumClassKey tycon)
- || (we_are_deriving ixClassKey tycon))
-
- = returnM ((con2tag_RDR tycon, tycon, GenCon2Tag)
- : acc_Names)
- | otherwise
- = returnM acc_Names
-
- do_tag2con acc_Names tycon
- | isDataTyCon tycon &&
- (we_are_deriving enumClassKey tycon ||
- we_are_deriving ixClassKey tycon
- && isEnumerationTyCon tycon)
- = returnM ( (tag2con_RDR tycon, tycon, GenTag2Con)
- : (maxtag_RDR tycon, tycon, GenMaxTag)
- : acc_Names)
- | otherwise
- = returnM acc_Names
-
- we_are_deriving clas_key tycon
- = is_in_eqns clas_key tycon all_CTs
- where
- is_in_eqns clas_key tycon [] = False
- is_in_eqns clas_key tycon ((c,t):cts)
- = (clas_key == classKey c && tycon == t)
- || is_in_eqns clas_key tycon cts
-\end{code}
-