[Haskell-cafe] Template Haskell examples?

Ian Lynagh igloo at earth.li
Thu Dec 6 15:30:42 EST 2007

On Tue, Dec 04, 2007 at 12:21:40PM -0500, Brent Yorgey wrote:
> I'm looking for good examples of using Template Haskell to evaluate CAFs at
> compile time, e.g. if I have some expensive-to-calculate lookup table which
> I'd rather have evaluated at comile time and included in the executable as a
> constant value, rather than having it computed every time the executable is
> run.  I know I've seen examples of this before, but now that I would
> actually like to study such an example, I can't seem to find any.  Any
> suggestions?  Or can anyone make up a simple example on the spot? =)

For any Lift'able type you can do something like this:

    import Language.Haskell.TH.Syntax

    foo = $( lift (not True) )

where "not True" is the CAF (and it cannot refer to functions defined in
the current module due to restrictions in teh TH implementation).


More information about the Haskell-Cafe mailing list