Skip to content

Haskell GHC Setup Guide — Install Haskell and Run Your First Program

DodaTech Updated 2026-06-28 2 min read

In this tutorial, you will learn about Haskell GHC Setup Guide. We cover key concepts, practical examples, and best practices to help you master this topic.

Haskell installation is managed through GHCup -- a tool that installs and manages GHC versions plus Cabal and Stack, providing everything needed to compile, test, and run Haskell programs.

Installing Haskell

# Using GHCup (recommended)
curl --proto '=https' --tlsv1.2 -sSf https://get-ghcup.haskell.org | sh

# This installs:
# - GHC (Glasgow Haskell Compiler)
# - Cabal (build system)
# - Stack (deterministic builds)
# - HLS (Haskell Language Server)

# Verify
ghc --version
cabal --version
stack --version

Your First Program

-- hello.hs
main :: IO ()
main = putStrLn "Hello, Haskell!"
# Run with GHCi (interpreter)
runhaskell hello.hs

# Compile with GHC
ghc -o hello hello.hs
./hello

GHCi Interactive

ghci
> 2 + 2
4
> :t True
True :: Bool
> :t putStrLn
putStrLn :: String -> IO ()
> :load hello.hs
> main
Hello, Haskell!

Cabal Projects

cabal init            # Create new project
cabal build           # Build project
cabal run             # Run executable
cabal repl            # GHCi with project context
cabal test            # Run tests

Common Mistakes

1. Installing without GHCup

Manual GHC installation is complex. GHCup handles everything.

2. Mixing Cabal and Stack projects

Choose one. Cabal is more flexible, Stack is more deterministic.

3. Ignoring HLS

Haskell Language Server provides IDE features. Install via GHCup.

FAQ

{{< faq question="What is the difference between Cabal and Stack?" >}} Both build Haskell projects. Stack provides deterministic builds (same deps every time). Cabal is more flexible. Many projects support both. {{< /faq >}}

{{< faq question="What is GHCi?" >}} The interactive Haskell Interpreter. It loads modules, evaluates expressions, and provides :type, :info, and debugging commands. {{< /faq >}}

{{< faq question="Can I run Haskell scripts without compiling?" >}} Yes. Use runhaskell script.hs to run interpreted without compiling to a binary. {{< /faq >}}

{{< faq question="What is HLS?" >}} Haskell Language Server provides IDE features (completion, Refactoring, diagnostics) for editors like VS Code and Vim. {{< /faq >}}

What's Next

Now learn about pure functions in Haskell.

Topic Description Link
Pure Functions Referential transparency {{< ref "03-pure-functions" >}}
Types Type system and inference {{< ref "04-types" >}}

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro