Skip to content

Instantly share code, notes, and snippets.

@MorrowM
Last active September 27, 2021 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MorrowM/e2101376591e212f86bb8f2591dd21ec to your computer and use it in GitHub Desktop.
Save MorrowM/e2101376591e212f86bb8f2591dd21ec to your computer and use it in GitHub Desktop.
Haskell Quickstart guide 2021

Haskell Quickstart Guide (as of September 2021)

Installation

On all platforms

  1. Install GHCup, this will manage all of your Haskell development tools. Follow the onscreen instructions. When it asks you if you'd like to install Haskell language server, say yes.
  2. Install the Haskell extension for VSCode. This is the front end for the Haskell Language Server (hls). If you'd like to use hls with another editor of your choice (any editor with lsp support), see this section of the hls documentation.

Creating your first Cabal project

  1. Navigate to an empty directory on the command line. Run cabal init. This will create 3 files:
    • A Changelog (you can ignore this for now)
    • A *.cabal file where * is the name of your cabal project (this defaults to the name of the directory you ran cabal init in). This file defines the structure of your project and which dependencies it uses.
    • An example source file, app/Main.hs. This is the entrypoint to your program.
  2. Run cabal run to compile and run your program. If all goes well, it should print Hello, Haskell!.
  3. To run a GHCi session in the context of your project, run cabal repl.

Glossary

  • GHC: The Glasgow Haskell Compiler, this is the program that turns Haskell (*.hs) source files into machine code.
  • GHCi: The GHC interactive environment. This is a tool for quickly evaluating expressions and interpreting programs in an interactive manner.
  • GHCup: The Haskell toolchain installer. This tool manages all the other tools you need to develop Haskell programs (GHC, Cabal, and HLS). Fun fact: If you're on Linux/Mac, you can run ghcup tui for a neat terminal UI.
  • Cabal: The Haskell build tool. This is a tool for building Haskell projects that may consist of more than 1 source file, and may have external dependencies from Hackage.
  • Hackage: The Haskell package repository. This is an external repository that hosts a large number of open source Haskell packages. You can browse Hackage packages here.
  • Haskell Language Server (HLS): The Haskell editor support backend. This tool is the backend for the Haskell IDE support in VSCode and other LSP-enabled editors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment