SafeLang12_B.hs 516 Bytes
Newer Older
dterei's avatar
dterei committed
1 2
{-# LANGUAGE Safe #-}
{-# LANGUAGE TemplateHaskell #-}
3
module SafeLang12_B ( Class(..), mkSimpleClass ) where
dterei's avatar
dterei committed
4 5 6 7 8 9 10 11

import Language.Haskell.TH

class Class a where
	c :: a

mkSimpleClass :: Name -> Q [Dec]
mkSimpleClass name = do
12
	TyConI (DataD [] dname [] Nothing cs _) <- reify name
dterei's avatar
dterei committed
13 14
	((NormalC conname []):_) <- return cs
	ClassI (ClassD [] cname [_] [] [SigD mname _]) _ <- reify ''Class
15
	return [InstanceD Nothing [] (AppT (ConT cname) (ConT dname)) [FunD mname
dterei's avatar
dterei committed
16 17
            [Clause [] (NormalB (ConE conname)) []]]]