[Template-haskell] RE: Why doesn't this program work?

Simon Peyton-Jones simonpj@microsoft.com
Mon, 13 Jan 2003 11:34:36 -0000


Thanks for the bug report.

Yes the template-haskell mailing list should work.  I'm ccing it.


| I compiled the following program with ghc-5.05.20030109
|=20
| ----------
|=20
| import Language.Haskell.THSyntax
|=20
| main =3D putStrLn (show $(lift ('a', 'b')))
|=20
| instance (Lift a, Lift b) =3D> Lift (a,b) where
|      lift (a,b) =3D tup [lift a, lift b]
|=20
| -----
|=20
| and received the following error message
|=20
| ghc-5.05.20030109: panic! (the `impossible' happened, GHC version
| 5.05.20030109):
|          nameModule zdfLiftZ2T{-a1dB-}

Well, the error message is appalling, and I'll improve it forthwith, but
the reason is simple: GHC doesn't allow you to call a locally-defined
function inside a top-level splice.  (It makes sense, but requires GHC
to compile code inconveniently early, for the module being compiled.)
So you have to put the instance decl in a separate module and compile
that first.

The error message will say so, shortly.

Simon