[Template-haskell] unexpected behaviour

François-Régis Sinot francois-regis.sinot@laposte.net
15 Apr 2003 03:00:35 +0200


Hello everybody

I am new to the list and intend to bother you a bit in the near future
with newbie questions --- my apologies in advance.

The following seems strange to me.
If I try:

data Tree a = Leaf a | Bin (Tree a) (Tree a)

out' :: Dec -> ()
out' _ = ()

outGen' :: Q [Dec]
outGen' = do d<-reifyDecl Tree 
	     dec1<-clause [pvar "x"] (normal [|out' d|]) []
	     return [Fun "out" [dec1]] 

I get an unexpected:
No instance for (Lift Dec) arising from use of `d'...

Whereas if I replace outGen' by:

foo :: Q ()
foo = do d<-reifyDecl Tree 
	 return (out' d)

outGen :: Q [Dec]
outGen = do dec1<-clause [pvar "x"] (normal [|foo|]) []
	    return [Fun "out" [dec1]] 

Then everything works OK.

Is it really a bug or just one of the numerous staging problems ?
Shouldn't everything derive Lift, by the way ? (if useful)

Now another thing: after writing some code randomly, I happened to
write foo like this:

foo :: Q ()
foo = do d<-reifyDecl Tree 
	 return $( [| out' d |] )

Because I meant that the "out' d" should really be executed _before_.
Now, I understand this was not really sensible (or was it ?).
However, ghc gives an ugly "panic!" message upon this, which is not
nice, and I suppose had to be reported.

Cheers,
fr.