Ticket #3916: TH.hs

File TH.hs, 543 bytes (added by nicolas.frisby, 4 years ago)

The splice for printing the TH kinds

Line 
1module TH where
2
3import Language.Haskell.TH.Syntax
4import Language.Haskell.TH.Ppr
5import Language.Haskell.TH.PprLib
6
7show_kinds :: Name -> Q [Dec]
8show_kinds name = do
9  info <- reify name
10  case info of
11    TyConI (DataD _ _ tvbs _ _) ->
12      (fail . show . hsep . map (parens . each)) tvbs
13      where each (PlainTV name) =
14              ppr name <+> colon <> colon <+> ppr StarK
15            each (KindedTV name kind) =
16              ppr name <+> colon <> colon <+> ppr kind
17    _ -> fail "show_kinds must be applied to a data declaration"