Skip to content

0007: Email Tutorials Haskell For Beginners ‐ Installing Haskell on Windows 10

Bernard Sibanda edited this page Dec 9, 2025 · 2 revisions

LigerLearn Video 7

📑 Table of Contents

  • 7.1. Goal: Setting Up Your Haskell Environment on Windows
  • 7.2. Installing Haskell and GHC Using GHCup
  • 7.3. Installing Optional Tools: HLS and Stack
  • 7.4. Verifying Your Installation from PowerShell
  • 7.5. Writing Your First Haskell Program (hello.hs)
  • 7.6. Compiling and Running with ghc
  • 7.7. Running Code Interactively with ghci
  • 7.8. When to Prefer ghci over Compiling
  • 7.9. Glossary of Terms for This Lesson

7.1. Goal: Setting Up Your Haskell Environment on Windows

In this lesson, you’ll go from having no Haskell setup on Windows to having a full working environment. This includes the GHC compiler, interactive GHCi, and related build tools. By the end, you’ll have compiled and run your first “Hello, World!” program and learned how to experiment quickly using ghci. The focus is specifically on Windows 10, using official tooling recommended by the Haskell community.

7.2. Installing Haskell and GHC Using GHCup

The recommended way to install Haskell on Windows is to use GHCup, a tool that manages Haskell installations for you.

  1. Open a web browser and go to: https://www.haskell.org/ghcup.
  2. On that page, you’ll see a code snippet in a box for Windows. Click the button that copies this command to your clipboard.
  3. Open a PowerShell window (normal user is fine; you do not need administrator privileges).
  4. Right-click in the PowerShell window to paste the command, then press Enter to run it.

At first, it may look like nothing is happening. The video mentions that it took about 20 seconds before any output appeared, so a short period of silence is normal. Once things start, you’ll see text explaining what can be installed and where.

7.3. Installing Optional Tools: HLS and Stack

The GHCup install script explains that it can install several tools:

  • GHC – the Glasgow Haskell Compiler.
  • GHCi – the interactive version of GHC.
  • Cabal – a build tool and package manager.
  • Haskell Language Server (HLS) – for editor/IDE integration.
  • Stack – another Haskell build tool and package manager.

In this setup, you:

  1. Accept the default installation paths on the C: drive by pressing Enter.
  2. Accept the default location for cabal.
  3. Choose to install the optional programs: Haskell Language Server and stack.

This gives you a complete Haskell platform on your system, suitable for building full applications and using feature-rich editors later. The installer may take a while—on the demo virtual machine it took around 25 minutes—but once it finishes, it will print a message indicating that everything is done.

7.4. Verifying Your Installation from PowerShell

After installation completes:

  1. Close any existing PowerShell windows used during install.
  2. Open a new PowerShell window, so your environment picks up the new PATH settings.

Now you can verify that the tools are available by asking each program what version it is running, using the --version flag. For example:

  • ghc --version – confirms the Glasgow Haskell Compiler is installed.
  • ghci --version – confirms the interactive GHCi is installed.
  • cabal --version – confirms the cabal build tool is available.
  • stack --version – confirms stack is installed.

Seeing version numbers printed means the commands are recognized and in your PATH, so your environment is ready.

7.5. Writing Your First Haskell Program (hello.hs)

Next, you write and run a simple Haskell program.

  1. In Windows, create a new file named hello.hs.

  2. Make sure you can see file extensions so you don’t accidentally create hello.hs.txt. The file must end exactly in .hs.

  3. Open hello.hs in a text editor. The video uses Notepad to keep things simple.

  4. Add the following code exactly:

    main = putStrLn "hello world"

    Note the capital letters in putStrLn (S and L are uppercase), and the "hello world" string is enclosed in double quotes.

  5. Save the file and close the editor.

This program defines a main function that prints "hello world" to the screen when executed.

7.6. Compiling and Running with ghc

Now you compile and run hello.hs using GHC:

  1. Open a PowerShell window in the directory where hello.hs is saved.

  2. Run the command:

    ghc -o hello hello.hs
    • The first hello after -o is the base name for the output files.
    • hello.hs is the source file you want to compile.
  3. After compilation, list the files in the directory again. You should see:

    • hello.hs – your source code.
    • hello.o – an object file produced during compilation.
    • hello.hi – an interface file produced by GHC.
    • hello.exe – the final executable program.
  4. Run hello.exe (e.g., .\hello from PowerShell). It should print:

    hello world
    

That’s your first compiled Haskell program running on Windows.

7.7. Running Code Interactively with ghci

Compiling and running is powerful, but when you’re learning, constantly recompiling for every tiny change can feel slow. This is where ghci comes in. It is an interactive Haskell environment (a REPL) where you can type code and see results immediately.

  1. In PowerShell, run:

    ghci
  2. At the ghci prompt, you can enter any valid Haskell expression or definition. For example, you can redefine:

    main = putStrLn "hello world"
  3. After defining main, type:

    main

    and press Enter. You’ll see the same "hello world" output printed in the terminal, just like with the compiled program.

  4. You can also try simple expressions like:

    2 + 2

    and GHCi will immediately evaluate and show the result.

  5. To leave ghci, type:

    :quit

    and press Enter.

7.8. When to Prefer ghci over Compiling

The lesson emphasizes that ghci is usually faster and more convenient when you are:

  • Experimenting with snippets of code.
  • Trying out small functions or expressions.
  • Learning new concepts and testing ideas interactively.

You can compile programs every time with ghc, but for most learning tasks, ghci saves you time and effort by avoiding full compilation on every small change. You’ll mostly use ghci throughout the course, while knowing that ghc is there when you want to build standalone executables.

7.9. Glossary of Terms for This Lesson

  • GHC (Glasgow Haskell Compiler) The standard Haskell compiler. It translates .hs source files into object files and executables such as hello.exe.

  • GHCi The interactive version of GHC. It provides a prompt where you can type Haskell code, define functions, and evaluate expressions immediately.

  • GHCup An installer and version manager for Haskell tools. On Windows, it automates downloading and installing GHC, GHCi, cabal, stack, and related components.

  • Cabal A Haskell build tool and package manager. It helps manage project dependencies and building more complex Haskell projects.

  • Stack Another Haskell build tool and project manager, often used for managing reproducible builds and larger projects.

  • Haskell Language Server (HLS) A background service that integrates with editors/IDEs to provide features like type information, error highlighting, and auto-completion for Haskell code.

  • PowerShell The Windows command-line shell used in this lesson to run installation commands, compiler commands, and executables.

  • .hs file A text file containing Haskell source code. By convention, all Haskell modules and scripts are stored in files ending with .hs.

  • Executable (.exe) The compiled binary produced by GHC on Windows, such as hello.exe, which you can run directly to execute your Haskell program.

  • REPL (Read–Eval–Print Loop) A style of interactive environment like ghci where you type expressions, they are evaluated, and the results are printed immediately.

Quizz & Progress Badge NFT

Clone this wiki locally