How to run a Haskell file in interpreted mode
You can have a script like this:
#!/usr/bin/env runhaskell
main = putStrLn "hello world"
After making the file executable (ie chmod +x haskell_script
), you can run it like any other shell script.
$ runhaskell MyFile.hs
Alternatively, runghc
(they're the same thing). ghci MyFile.hs
will also start an interactive REPL session with MyFile.hs
loaded, but if you want to run a main program then runhaskell
is the way to go.
It's probably a good idea to get into the habit of testing parts of your program as isolated units in GHCi rather than running the whole thing each time, but obviously for shorter scripts it's simplest and easiest just to run the entire thing.