LinuxCommandLibrary

runghc

TLDR

Run Haskell script

$ runghc [script.hs]
copy
Run with arguments
$ runghc [script.hs] [arg1] [arg2]
copy
Specify GHC version
$ runghc-[8.10] [script.hs]
copy
With GHC options
$ runghc -- -O2 [script.hs]
copy

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
copy

SCRIPT EXAMPLE

$ #!/usr/bin/env runghc
import System.Environment

main = do
    args <- getArgs
    putStrLn $ "Hello, " ++ head args
copy

ALTERNATIVES

$ runhaskell  # Synonym
ghci        # Interactive (load with :load)
ghc -e      # One-liner
copy

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.

SEE ALSO

ghc(1), ghci(1), cabal(1), stack(1)

Copied to clipboard