How to run a Haskell file in interpreted mode

Joshua Cheek picture Joshua Cheek · Dec 30, 2011 · Viewed 35.3k times · Source

I've been told you can interpret Haskell files (which I assume means they will work like Ruby/Python/Perl). I can't find the command line option on GHC to do this, though. It always wants to compile my file. Took a look at GHCi as well, but it always dumps me into a repl.

I'm basically wanting to just do ghc -i MyFile.hs (where -i is a made up flag that I'm pretending correllates to interpreted mode) and have it execute so that I can get quick feedback while I'm trying out ideas and learning.

Answer

ehird picture ehird · Dec 30, 2011
$ 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.