[Haskell-cafe] Cabal and Strings and CPP

Philip Weaver philip.weaver at gmail.com
Mon Jul 28 18:02:21 EDT 2008


Hello all,

I'm trying to use CPP-defined strings in a Haskell module, like this:

   main :: IO ()
   main = putStrLn FOO

This of course will not work:

   ghc -DFOO="hello world" --make Main.hs -o test

You'll get this error message:

   ./Main.hs:6:16: Not in scope: `hello'
   ./Main.hs:6:22: Not in scope: `world'

Either of these will do what I want:

   ghc -DFOO="\"hello world\"" --make Main.hs -o test

   ghc -DFOO='"hello world"' --make Main.hs -o test  # (that's double quotes
inside single quotes)

However, passing the same CPP definition via cabal does not work.

   runhaskell Setup.hs build --ghc-options=-DFOO="\"hello world\""

   runhaskell Setup.hs build --ghc-options=-DFOO='"hello world"'

With either of these commands, I get the same error message as above.  This
is understandable, since cabal has to evaluate the string before sending it
to GHC, so I lose my escaped quotes.

Any idea how I could change the Haskell module or the command line argument
so that I get what I want?  I've tried many combinations of quotes and
escaped quotes with no luck.

Thanks,
- Phil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20080728/e5d02c65/attachment.htm


More information about the Haskell-Cafe mailing list