Question

I have a trivial Template Haskell program that prints the name of the current module (Main, here):

{-# LANGUAGE TemplateHaskell #-}
module Main
( main
) where

import Language.Haskell.TH
import Language.Haskell.TH.Syntax

modName ∷ String
modName = $(fmap loc_module qLocation »= λmod → return (LitE (StringL mod) ))

main ∷ IO ()
main = putStrLn modName

When I compile this, I get the following Loading messages from ghc:

tsuraan@localhost ~/test/modname $ ghc --make Main
[1 of 1] Compiling Main             ( Main.hs, Main.o )
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package array-0.4.0.0 ... linking ... done.
Loading package deepseq-1.3.0.0 ... linking ... done.
Loading package containers-0.4.2.1 ... linking ... done.
Loading package pretty-1.1.1.0 ... linking ... done.
Loading package template-haskell ... linking ... done.
Linking Main ...

Why does ghc load all these packages when Template Haskell is enabled? Whenever I build a program that uses Template Haskell, especially one that is built against a lot of packages, my compile warnings are overwhelmed with these superfluous "Loading" messages. It would be nice if I could stop the messages from being printed, or stop the (unnecessary?) module loading from happening at all.

Was it helpful?

Solution

Template Haskell runs at compile time, via a bytecode interpreter (GHCi). Any package dependencies that you have -- at compile time -- will be loaded dynamically into GHC -- at compile time, so that you can execute your splices.

One of your dependencies is the Template Haskell library itself, which in turn depends on most of the core things.

OTHER TIPS

You can prevent the "Loading package" lines from being printed by passing the -v0 flag to GHC. (This also suppresses the "Compiling" and "Linking" lines, but warnings and errors are still shown.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top