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