runghc from standard input and --ghc-args
I am trying to use runghc with a cabal sandbox, and it works when the haskell code is in a file like follows:
runghc -- -package-db --ghc-arg=.cabal-sandbox/i386-linux-ghc-7.6.3-packages.conf.d somefile.hs
But if I try and load the script from standard input (actually I am trying to run a GHC script from a bash script using "runghc << EOF" but it is easier to see if you just run from the console)
runghc -- -package-db --ghc-arg=.cabal-sandbox/i386-linux-ghc-7.6.3-packages.conf.d < somefile.hs
you get an error
.cabal-sandbox/i386-linux-ghc-7.6.3-packages.conf.d/:1:57:
Not in scope: `main'
Perhaps you meant `min' (imported from Prelude)
Looking at the utils/runghc/runghc.hs source file, what happens is inside the doIt function. The first thing the doIt function does is call getGhcArgs which strips the --ghc-args. Then it checks the args and sees there is no file, so falls into the case where it reads standard input, creates a temp file, and then recalls doIt. Here is the problem, because the "--ghc-arg" string has already been stripped so the second call to doIt is where the error occurs.
With that, I can actually get it to work with the following :)
runghc -- -package-db --ghc-arg=--ghc-arg=.cabal-sandbox/i386-linux-ghc-7.6.3-packages.conf.d < somefile.hs
By passing --ghc-arg= twice, it is stripped once the first time doIt is called and once the second time and GHC gets the correct args :)
Trac metadata
| Trac field | Value |
|---|---|
| Version | 7.6.3 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |