Can't use both shebang line and #ifdef declarations in the same file.
|Reported by:||gfxmonk||Owned by:|
|Type of failure:||GHC rejects valid program||Test Case:|
|Related Tickets:||Differential Rev(s):|
I have an (admittedly awkward) script which can be compiled or interpreted.
If it's compiled, I want the full goodness. If it's interpreted, I want to run a "minimal" version (because if I don't have the compiled version, I probably don't have the required libraries either).
The following almost works:
module Main (main) where #ifdef FANCY import qualified System.Console.ANSI as Term start = Term.setSGR [Term.SetColor Term.Foreground Term.Dull Term.Green] end = Term.setSGR  #else start = return () end = return () #endif main :: IO () main = do start putStrLn "hello world" end
and then I can do:
$ runghc -cpp main.hs hello world ^^ plain text
$ ghc -O -cpp -DFANCY main.hs $ ./main hello world ^^ green text (a.k.a "fancy")
I attempted to make this directly runnable by adding a shebang line of
But unfortunately that chokes with -cpp:
$ ghc -O -cpp -DFANCY main.hs main.hs:1:0: error: invalid preprocessing directive #!