Can't use both shebang line and #ifdef declarations in the same file.
|Reported by:||gfxmonk||Owned by:|
|Operating System:||MacOS X||Architecture:||Unknown/Multiple|
|Type of failure:||GHC rejects valid program||Test Case:||runghc/T6132|
|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 #!
Change History (15)
comment:8 Changed 8 months ago by thomie
- Resolution set to fixed
- Status changed from new to closed
- Test Case set to runghc/T6132
comment:10 Changed 3 weeks ago by bgamari
- Milestone set to 8.0.2
- Resolution fixed deleted
- Status changed from closed to new