d43923181539077485454704f5a9ed02783ca780
[ghc.git] / testsuite / tests / th / TH_genExLib.hs
1
2 module TH_genExLib where
3
4 import Language.Haskell.TH
5
6 genAny :: Q Info -> Q [Dec]
7 genAny decl = do { d <- decl
8 ; case d of
9 ClassI (ClassD _ name _ _ decls) _ -> return [genAnyClass name decls]
10 _ -> error "genAny can be applied to classes only"
11 }
12
13 genAnyClass :: Name -> [Dec] -> Dec
14 genAnyClass name decls
15 = DataD [] anyName [] [constructor] []
16 where
17 anyName = mkName ("Any" ++ nameBase name ++ "1111")
18 constructor = ForallC [PlainTV var_a] [AppT (ConT name) (VarT var_a)] $
19 NormalC anyName [(NotStrict, VarT var_a)]
20 var_a = mkName "a"