Commit c4592b62 authored by simonpj's avatar simonpj

[project @ 2004-12-23 09:37:01 by simonpj]

Add a test involving existentials
parent aaf9f205
{-# OPTIONS -fglasgow-exts #-}
module TH_genEx where
import TH_genExLib
import Language.Haskell.TH
class MyInterface a where
foo :: a -> Int
foo1 :: Int -> a -> Int
$(genAny (reify ''MyInterface))
Chasing modules from: TH_genEx
Compiling TH_genExLib ( ./TH_genExLib.hs, ./TH_genExLib.o )
Compiling TH_genEx ( TH_genEx.hs, TH_genEx.o )
TH_genEx.hs:1:0:
TH_genEx.hs:1:0: Splicing declarations
genAny (reify 'MyInterface)
======>
data AnyMyInterface1111
= forall a. (TH_genEx.MyInterface a) => AnyMyInterface1111 a
Warning: output was redirected with -o, but no output will be generated
because there is no Main module.
Loading package base-1.0 ... linking ... done.
Loading package haskell98-1.0 ... linking ... done.
Loading package template-haskell-1.0 ... linking ... done.
{-# OPTIONS -fglasgow-exts #-}
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 [var_a] [AppT (ConT name) (VarT var_a)] $
NormalC anyName [(NotStrict, VarT var_a)]
var_a = mkName "a"
......@@ -34,5 +34,6 @@ test('TH_bracket2', normal, compile, [''])
test('TH_bracket3', normal, compile, [''])
test('TH_class1', normal, compile, [''])
test('TH_genEx', normal, multimod_compile, ['TH_genEx', '-ddump-splices'])
test('TH_where', normal, compile_and_run, [''])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment