Lemmih | 4 Jul 22:45 2005
Picon

Re: Avoiding linking final executable to TH

On 7/4/05, Einar Karttunen <ekarttun <at> cs.helsinki.fi> wrote:
> Hello
> 
> Are there currently any plans to avoid linking the final executable with
> TH? As far as I understand currently the situation is as follows:
> 
> Module M uses TH code defined in MTH.
> Module MTH imports TH modules and thus needs to be linked with template-haskell.
> 
> The simplest way to deal with this could be to use a special
> compile-time import construct between M and MTH - so that MTH would
> not need to be linked with M (and thus template-haskell would not be
> needed either).
> 
> Are there any plans regarding something like this or an another solution?

I hacked up Zeroth to overcome the linking problem. Zeroth is a
preprocessor which scans Haskell source files (using haskell-src-exts)
for top level splices and evaluates them. For example:

> module TestTH where
> #ifdef HASTH
> -- import TH modules here.
> #endif
> -- Simple declaration
> $( [d| x = "test" |] )

becomes

> module TestTH
> -- Simple declaration
> x = "test"

However, Zeroth is hardly more than a dirty fix so use with care.

Darcs repository: http://www.scannedinavian.org/~lemmih/zerothHead
Haskell-src-exts: http://www.cs.chalmers.se/%7Ed00nibro/haskell-src-exts/
I've attached a patch with Cabal support for zeroth.

--

-- 
Friendly,
  Lemmih
Attachment (zeroth.patch): text/x-patch, 19 KiB
_______________________________________________
template-haskell mailing list
template-haskell <at> haskell.org
http://www.haskell.org/mailman/listinfo/template-haskell

Gmane