
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

On Mon, 2008-07-28 at 15:02 -0700, Philip Weaver wrote:
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.
Cabal has both --prog-option= and --prog-options=. The latter tokenises the options and passes them as separate flags (like what the shell does), the former passes the whole arg as one option. So you want to use: cabal build --ghc-option=-DFOO="\"hello world\"" When you want to put this in the .cabal file, use cpp-options (not ghc-options) and you can use Haskell String syntax for options that contain spaces. Duncan

"Philip Weaver"
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
Have you tried using ANSI cpp's stringification operator? {-# LANGUAGE CPP #-} #define STRING(bar) #bar main :: IO () main = putStrLn FOO ghc -DFOO="STRING(hello world)" --make Main.hs -o test Regards, Malcolm

On Tue, Jul 29, 2008 at 3:14 AM, Malcolm Wallace < Malcolm.Wallace@cs.york.ac.uk> wrote:
"Philip Weaver"
wrote: 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
Have you tried using ANSI cpp's stringification operator?
{-# LANGUAGE CPP #-} #define STRING(bar) #bar main :: IO () main = putStrLn FOO
ghc -DFOO="STRING(hello world)" --make Main.hs -o test
Yes, I have. It does not seem to be supported.
Regards, Malcolm _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (3)
-
Duncan Coutts
-
Malcolm Wallace
-
Philip Weaver