LinuxCommandLibrary

runghc

Run Haskell programs without compilation

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 source files directly without a separate compilation step, making it ideal for scripting and quick prototyping. It invokes GHC (Glasgow Haskell Compiler) behind the scenes to compile the program to a temporary location and execute it immediately, providing a scripting-like experience for Haskell code.
The tool supports shebang lines (#!/usr/bin/env runghc), enabling Haskell files to be used as executable scripts. Command-line arguments after the filename are passed to the Haskell program, and GHC options can be specified before a -- separator. The synonym runhaskell is also available.

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)

> TERMINAL_GEAR

Curated for the Linux community

Copied to clipboard

> TERMINAL_GEAR

Curated for the Linux community