Haskell Stack is a tool used to build Haskell projects and to handle its dependencies, including GHC, Cabal, a version of the Hackage repository, and a version of the Stackage package collection tool. In this chapter, you will learn the main uses of Haskell Stack.
In Windows, go to https://get.haskellstack.org/stable/windows-x86_64-installer.exe , where you will be prompted to download the installer. Then follow the steps in the installer.
stack new: Creates a new directory and all the necessary files to begin a project. The structure will look like Figure 23-1.
stack setup: Downloads the compiler if needed, putting it in a separate location. This means it won’t make changes outside its directory.
stack build: Builds a minimal project, designing reproducible builds. In this process, curated package sets are used, called snapshots. The main directory contains a file called stack.yaml representing a blueprint. It contains a reference called resolver that points to the snapshot used in the build process.
stack exec my-project-exe: Executes a command.
Another useful command is stack install <package_name> , which installs a desired package. And, of course, don’t forget about stack --help, which provides all the commands.
Now let’s see a concrete example, called hello-world, inspired from [1] (note that, in this example, we will work on the Windows operating system).
In this step, Stack will check for GHC and will download and install it into the global Stack root directory. This will take a while, and you will get intermediary messages about the download progress. After the build process, a library called hello-world and an executable called hello-world-exe are created in the autocreated directory .stack-work in the hello-world directory.
You will get a someFunc message.
You have created a simple project with the Haskell tool Stack.
The Haskell tool Stack is great for versioning control, focusing on reproducible build plans and multipackage projects. Of course, you can do a lot more things with it than what was presented in this chapter. For example, you can put your project into a Git repository, or you can include other projects from Git. You can find a comprehensive tutorial in [1].
Summary
What the Haskell tool Stack is
What the main commands are and what they mean
How to create, build, run, and test a new project
How to add new dependencies to the project
References
- 1.
User guide, https://docs.haskellstack.org/en/stable/GUIDE/
- 2.
The Haskell Tool Stack, https://docs.haskellstack.org/en/stable/README/