tags:

views:

449

answers:

4

I'm writing some disposable Haskell scripts to solve some of the Project Euler problems. I don't really want to have to compile them because of the number of changes I'm constantly having to make, but in a few cases I've found that I've run out of stack space.

The documentation for runhaskell says that the following syntax should increase the stack space:

runhaskell +RTS -K5M -RTS Script.hs

This never, ever works (in any permutation I've tried). The stack size always remains 8,388,608. This is maddening, and I haven't found much help on Google.

Any suggestions? What am I doing wrong?

+3  A: 

I'm guessing you're using GHC. Chapter 4 of the User's Guide of the newly released 6.10.1 says:

The only runghc flag currently is -f /path/to/ghc, which tells runghc which GHC to use to run the program.

I don't see a bug logged at http://hackage.haskell.org/trac/ghc . Seems pretty lame to me. I'd suggest asking on irc #ghc, or the cvs-ghc mailing list.

Of the other Haskell compilers/interpreters, only nhc98 seems allow you to set the max stack size. Depending on your OS, nhc98 could be an option.

ja
A: 

Just compile it.

Problem123.hs:

module Main where
main = do
    print solution
solution = ...

Short and sweet command line:

ghc --make -O3 Problem123.hs
./Problem123

Final note: I'm not sure I would call them "scripts".

Justice
Yeah, It's easy enough to compile using --make. However, it's even easier to hit R in TextMate on OS X and have the file executed with runhaskell. When you're hacking away and constantly changing things, it's just easier.
Gregory Higley
Scripting has always been one of the design goals of Haskell, and calling programs scripts is fairly common, for example: http://groups.google.com/group/comp.lang.functional/browse_thread/thread/5a6df7d9b550346f?hl=en
ja
A: 

I'm doing the same thing (Project Euler) and have been using ghc. The trick (thanks #haskell!) is to tell the EXECUTABLE to have more stack size rather than the COMPILER.

$ ghc -O2 -o 23 23.hs
$ ./23 +RTS -K128M

A: 

Justice - if we're being pedantic, 'script' is exactly the right word to use. That's what the 's' in '.hs' stands for.

I agree though that 'script' is a bit misleading, as it suggests an interpreted program that does something. Maybe we should call them 'source files' instead.