March 20, 2023

Setting Up Haskell (日本語)

Haskell is a powerful programming language that has undergone many changes over the year. If you are looking to set up Haskell for the first time or revisit it after a long break, there are two popular ways to do so: stack and GHCup. I will explore both options and recommend a suitable approach.

Before stack

ghc is the popular compiler used to build Haskell projects. While it is great for compiling single source files, building large projects with multipile source files can be a challenge.

To simplify this process, Haskell programmers developed cabal, a wrapper for ghc that could build a project and download any necessary Haskell projects. However, cabal itself became complecated to use as projects grew larger and resolving external dependencies became increasingly difficult.

What is stack?

In response to these challenges, stack was created as an improved version of cabal. It offers the following advantages.

  1. Options to help build larger projects

  2. Metadata to resolve dependencies, license, project description, and so on.

  3. The ability to control ghc versions

Initially, stack used file named package.yaml to write the metadata, but it uses <package-name>.cabal as well today. Programmers should write one of them, however, the spec of package.yaml is not updated as frequently as <package-name>.cabal. Therefore, I recommend to use only <package-name>.cabal strongly.

What is GHCup?

GHCup is a setup tool for Haskell to install ghc, cabal, and stack.

While cabal has been updated over time, there are few differences between it and stack today, except that cabal does not install ghc. In this sense, there is no significant difference between cabal and stack if both are installed through GHCup.


If you are looking to set up Haskell today, there are three popular options:

  1. Install stack directly and use it.

  2. Set up via GHCup and use stack.

  3. Set up via GHCup and use cabal.

I recommend the third option, "Setting up via GHCup and using cabal," for the following reasons.

  1. GHCup is a better option for setting up Haskell as it follows for the use of both stack and cabal.

  2. Haskell Platform, which was the de facto standard 15 years ago, recommends using GHCup.

  3. While the differences between cabal and stack are small, cabal is preferred because stack has two metadat files, package.yaml and <package-name>.cabal, violating the principle of "Don't Repeat Yourself (DRY)."

I hope that this guide has provided you with the information you need to choose the best option for your needs.