Search code examples
haskellscriptingghci

Does Haskell's ghci support running a script and then quit, like python or perl?


Python or Perl supports:

python xxx.py
perl xxx.pl
powershell xxx.ps1

Execute the script and quit with an exit code. When I tried GHCi (as ghci xxx.hs) it seems to load the xxx.hs file and enter interactive mode, without quiting.

  1. Does the GHC interpreter support such operations?
  2. Does this "interpreting" require to have a main function like the GHC compiler does?

Solution

  • Use runghc to get the same behavior. You will indeed need a main :: IO () function still.