
cat Test.hs import System
Hello, I want to use ghc as a script interpreter, using the '-e' option. The problem is that I can't give the script any command line arguments, because 'ghc -e' intepretes everything argument as the name of a module to compile. main = getArgs >>= print
ghc -e Main.main Test.hs [] ghc -e Main.main Test.hs blabla Can't find module `blabla' (use -v to see a list of the files searched for)
<interactive>:1: Failed to load interface for `Main': Bad interface file: Test.hi Test.hi: openBinaryFile: does not exist (No such file or directory) <interactive>:1: Variable not in scope: `Main.main' Is there a way to tell ghc that what follows are arguments to teh program ('main') and not to ghc itself? Ben

On Wed, 17 Nov 2004, Benjamin Franksen wrote:
I want to use ghc as a script interpreter, using the '-e' option. The problem is that I can't give the script any command line arguments, because 'ghc -e' intepretes everything argument as the name of a module to compile.
I once wrote a script which circumvented the issue above by using System.Environment.withArgs. It works, but it is of course a little clunky. See the attached sources. /NAD

On Wednesday 17 November 2004 15:06, Nils Anders Danielsson wrote:
On Wed, 17 Nov 2004, Benjamin Franksen wrote:
I want to use ghc as a script interpreter, using the '-e' option. The problem is that I can't give the script any command line arguments, because 'ghc -e' intepretes everything argument as the name of a module to compile.
I once wrote a script which circumvented the issue above by using System.Environment.withArgs. It works, but it is of course a little clunky.
See the attached sources.
Thanks a lot! I needed to modify it a little to suit my preferences but it works like a charm. BTW, it seems as if ghc already ignores a first line starting with "#!", which makes the program a bit simpler. What about putting this thing on the Haskell Wiki? Cheers, Ben PS: Sorry for the delayed answer.

On Wed, 24 Nov 2004, Benjamin Franksen wrote:
What about putting this thing on the Haskell Wiki?
Feel free to do so. I recently noted that some version of GHC (6.3?) ships with a runghc program, so this problem will most likely disappear soon, though. http://cvs.haskell.org/cgi-bin/cvsweb.cgi/~checkout~/fptools/ghc/utils/rungh... /NAD

On Wednesday 24 November 2004 02:39, Nils Anders Danielsson wrote:
On Wed, 24 Nov 2004, Benjamin Franksen wrote:
What about putting this thing on the Haskell Wiki?
Feel free to do so. I recently noted that some version of GHC (6.3?) ships with a runghc program, so this problem will most likely disappear soon, though.
http://cvs.haskell.org/cgi-bin/cvsweb.cgi/~checkout~/fptools/ghc/utils/rung hc/runghc.hs
Nice to hear that. Publishing the code is obsolete then. Ben
participants (2)
-
Benjamin Franksen
-
Nils Anders Danielsson