Where is the mate to the Sock?¶
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.
Options to help build larger projects
Metadata to resolve dependencies, license, project description, and so on.
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.
Conclusion¶
If you are looking to set up Haskell today, there are three popular options:
Install stack directly and use it.
Set up via GHCup and use stack.
Set up via GHCup and use cabal.
I recommend the third option, "Setting up via GHCup and using cabal," for the following reasons.
GHCup is a better option for setting up Haskell as it follows for the use of both stack and cabal.
Haskell Platform, which was the de facto standard 15 years ago, recommends using GHCup.
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.
The latest articles¶
Debian Bullseye の GUI をセットアップ (Japanese)
Setup GUI for Debian Bullseye (English)
"The Rust Programming Language" を読む (日本語)
Reading "The Rust Programming Language" (English)
Rust の Crate で Features を使う (日本語)
Adding Features to a Rust Crate (English)