+%
+% (c) The University of Glasgow 2006
+%
+
\begin{code}
+{-# OPTIONS -fno-warn-incomplete-patterns #-}
+-- The above warning supression flag is a temporary kludge.
+-- While working on this module you are encouraged to remove it and fix
+-- any warnings in the module. See
+-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
+-- for details
+
module Generics ( canDoGenerics, mkTyConGenericBinds,
mkGenericRhs,
validGenericInstanceType, validGenericMethodType
import HsSyn
-import Type ( Type, isUnLiftedType, tyVarsOfType,
- isTyVarTy, getTyVar_maybe, funTyCon
- )
-import TcHsSyn ( mkSimpleHsAlt )
-import TcType ( tcSplitTyConApp_maybe, tcSplitSigmaTy, tcSplitPhiTy, applyTy,
- isTauTy, mkTyVarTy )
-import DataCon ( DataCon, dataConOrigArgTys, isVanillaDataCon,
- dataConSourceArity )
-
-import TyCon ( TyCon, tyConName, tyConDataCons,
- isBoxedTupleTyCon
- )
-import Name ( nameModule, nameOccName, getSrcLoc )
-import OccName ( mkGenOcc1, mkGenOcc2 )
-import RdrName ( RdrName, getRdrName, mkVarUnqual, mkOrig )
-import BasicTypes ( EP(..), Boxity(..) )
-import Var ( TyVar )
-import VarSet ( varSetElems )
-import Id ( Id, idType )
-import TysWiredIn ( listTyCon )
+import Type
+import TcHsSyn
+import TcType
+import DataCon
+
+import TyCon
+import Name
+import OccName
+import RdrName
+import BasicTypes
+import Var
+import VarSet
+import Id
+import TysWiredIn
import PrelNames
-import SrcLoc ( srcLocSpan, noLoc, Located(..) )
-import Util ( takeList, isSingleton )
+import SrcLoc
+import Util
import Bag
import Outputable
import FastString
mkGenericLocal :: US -> RdrName
mkGenericLocal u = mkVarUnqual (mkFastString ("g" ++ show u))
+mkGenericNames :: TyCon -> (RdrName, RdrName)
mkGenericNames tycon
= (from_RDR, to_RDR)
where
-------------------
-- bimapArrow :: [EP a a', EP b b'] -> EP (a->b) (a'->b')
+bimapArrow :: [EP (LHsExpr RdrName)] -> EP (LHsExpr RdrName)
bimapArrow [ep1, ep2]
= EP { fromEP = mkHsLam [nlVarPat a_RDR, nlVarPat b_RDR] from_body,
toEP = mkHsLam [nlVarPat a_RDR, nlVarPat b_RDR] to_body }
-------------------
-- bimapTuple :: [EP a1 b1, ... EP an bn] -> EP (a1,...an) (b1,..bn)
+bimapTuple :: [EP (LHsExpr RdrName)] -> EP (LHsExpr RdrName)
bimapTuple eps
= EP { fromEP = mkHsLam [noLoc tuple_pat] (noLoc from_body),
toEP = mkHsLam [noLoc tuple_pat] (noLoc to_body) }
-------------------
-- bimapList :: EP a b -> EP [a] [b]
+bimapList :: [EP (LHsExpr RdrName)] -> EP (LHsExpr RdrName)
bimapList [ep]
= EP { fromEP = nlHsApp (nlHsVar map_RDR) (fromEP ep),
toEP = nlHsApp (nlHsVar map_RDR) (toEP ep) }
-------------------
+a_RDR, b_RDR :: RdrName
a_RDR = mkVarUnqual FSLIT("a")
b_RDR = mkVarUnqual FSLIT("b")
+
+gs_RDR :: [RdrName]
gs_RDR = [ mkVarUnqual (mkFastString ("g"++show i)) | i <- [(1::Int) .. ] ]
idEP :: EP (LHsExpr RdrName)