runghc
TLDR
Run Haskell script
$ runghc [script.hs]
Run with arguments$ runghc [script.hs] [arg1] [arg2]
Specify GHC version$ runghc-[8.10] [script.hs]
With GHC options$ runghc -- -O2 [script.hs]
SYNOPSIS
runghc [options] [ghc-options] file [args]
DESCRIPTION
runghc runs Haskell programs without compiling them first. It's useful for scripts and quick tests, invoking GHC to compile to memory and execute immediately.
Part of GHC (Glasgow Haskell Compiler).
PARAMETERS
--
Separator for GHC options.-f file
Use different GHC.--help
Show help.--version
Show version.
EXAMPLES
$ # Run script
runghc hello.hs
# With arguments
runghc calculator.hs 2 + 3
# Pass GHC options
runghc -- -Wall script.hs
# Shebang usage
#!/usr/bin/env runghc
runghc hello.hs
# With arguments
runghc calculator.hs 2 + 3
# Pass GHC options
runghc -- -Wall script.hs
# Shebang usage
#!/usr/bin/env runghc
SCRIPT EXAMPLE
$ #!/usr/bin/env runghc
import System.Environment
main = do
args <- getArgs
putStrLn $ "Hello, " ++ head args
import System.Environment
main = do
args <- getArgs
putStrLn $ "Hello, " ++ head args
ALTERNATIVES
$ runhaskell # Synonym
ghci # Interactive (load with :load)
ghc -e # One-liner
ghci # Interactive (load with :load)
ghc -e # One-liner
CAVEATS
Slower than compiled code. Recompiles each run. For performance, use ghc to compile.
HISTORY
runghc is part of GHC (Glasgow Haskell Compiler), the primary Haskell compiler developed by the GHC team.


