1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407
|
<div class="hidden-warning"><a href="https://docs.haskellstack.org/"><img src="https://cdn.jsdelivr.net/gh/commercialhaskell/stack/doc/img/hidden-warning.svg"></a></div>
# The Haskell Tool Stack
Welcome to the [Haskell](https://www.haskell.org/) programming language and the
Haskell Tool Stack (Stack)! Stack is a program for developing Haskell projects.
It is aimed at Haskellers both new and experienced. It is cross-platform and
aims to support fully users on Linux, macOS and Windows.
<img src="https://i.imgur.com/WW69oTj.gif" width="50%" align="right">
Stack features:
* Installing the [Glasgow Haskell Compiler (GHC)](https://www.haskell.org/ghc/)
automatically, in an isolated location.
* Installing packages needed for your project.
* Building your project.
* Testing your project.
* Benchmarking your project.
## How to install Stack
Stack can be installed on most Unix-like operating systems (including macOS) and
Windows. It will require at least about 5 GB of disk space, for use with one
version of GHC.
!!! info
In addition to the methods described below, Stack can also be installed
using the separate [GHCup](https://www.haskell.org/ghcup/) installer for
Haskell-related tools. GHCup provides Stack for some combinations of machine
architecture and operating system not provided elsewhere. By default, the
script to install GHCup (which can be run more than once) also configures
Stack so that if Stack needs a version of GHC, GHCup takes over obtaining
and installing that version.
=== "Linux"
For most Linux distributions, the easiest way to install Stack
directly (rather than use GHCup) is to command:
~~~text
curl -sSL https://get.haskellstack.org/ | sh
~~~
or:
~~~text
wget -qO- https://get.haskellstack.org/ | sh
~~~
!!! note
The script at [get.haskellstack.org](https://get.haskellstack.org/) will
ask for root access using `sudo`. It needs such access in order to use
your platform's package manager to install dependencies and to install
to `/usr/local/bin`. If you prefer more control, follow the manual
installation instructions in the
[install and upgrade guide](install_and_upgrade.md).
=== "macOS"
From late 2020, Apple began a transition from Mac computers with Intel
processors (Intel-based Mac) to
[Mac computers with Apple silicon](https://support.apple.com/en-gb/HT211814).
=== "Intel-based"
For most Intel-based Mac computers, the easiest way to install Stack
directly (rather than use GHCup) is to command:
~~~text
curl -sSL https://get.haskellstack.org/ | sh
~~~
or:
~~~text
wget -qO- https://get.haskellstack.org/ | sh
~~~
!!! note
The script at [get.haskellstack.org](https://get.haskellstack.org/)
will ask for root access using `sudo`. It needs such access in order
to use your platform's package manager to install dependencies and
to install to `/usr/local/bin`. If you prefer more control, follow
the manual installation instructions in the
[install and upgrade guide](install_and_upgrade.md).
=== "Apple silicon"
Mac computers with Apple silicon have an M1, M1 Pro, M1 Max, M1 Ultra or
M2 chip. These chips use an architecture known as ARM64 or AArch64.
For Mac computers with Apple silicon, the easiest way to install Stack
directly (rather than use GHCup) is to command:
~~~text
curl -sSL https://get.haskellstack.org/ | sh
~~~
or:
~~~text
wget -qO- https://get.haskellstack.org/ | sh
~~~
!!! note
The script at [get.haskellstack.org](https://get.haskellstack.org/)
will ask for root access using `sudo`. It needs such access in order
to use your platform's package manager to install dependencies and
to install to `/usr/local/bin`. If you prefer more control, follow
the manual installation instructions in the
[install and upgrade guide](install_and_upgrade.md).
=== "Windows"
On 64-bit Windows, the easiest way to install Stack directly (rather than
use GHCup) is to download and install the
[Windows installer](https://get.haskellstack.org/stable/windows-x86_64-installer.exe).
!!! info
By default, the Windows installer will set the Stack root to `C:\sr`.
!!! warning
The Windows installer for Stack 2.9.1, 2.9.3 and 2.11.1 (only) will
replace the user `PATH` environment variable (rather than append to it)
if a 1024 character limit is exceeded. If the content of your existing
user `PATH` is long, preserve it before running the installer.
!!! note
Systems with antivirus software may need to add Stack to the list of
'trusted' applications.
=== "Other/direct downloads"
For other operating systems and direct downloads (rather than use GHCup),
see the [install and upgrade guide](install_and_upgrade.md).
## How to upgrade Stack
If Stack is already installed, you can upgrade it to the latest version by the
command:
~~~text
stack upgrade
~~~
!!! note
If you used [GHCup](https://www.haskell.org/ghcup/) to install Stack, you
should also use GHCup, and not Stack, to upgrade Stack.
## Quick Start guide
For an immediate experience of using Stack to build an executable with Haskell,
first you need to follow the [guide to install Stack](#how-to-install-Stack).
### Step 1: Start your new project
To start a new project named `my-project`, issue these four commands in a
terminal:
~~~text
stack new my-project
cd my-project
stack build
stack exec my-project-exe
~~~
- The `stack new my-project` command will create a new directory, named
`my-project`. It contains all the files needed to start a project correctly,
using a default template.
- The `cd my-project` command will change the current working directory to that
directory.
- The `stack build` command will build the template project and create an
executable named `my-project-exe` (on Windows, `my-project-exe.exe`). First,
if necessary, Stack will download a version of GHC in an isolated location.
That won't interfere with other GHC installations on your system.
- The `stack exec my-project-exe` command will run (execute) the built
executable, in Stack's environment.
For a complete list of Stack's commands, and flags and options common to those
commands, simply command:
~~~text
stack
~~~
For help on a particular Stack command, including flags and options specific to
that command, for example `stack build`, command:
~~~text
stack build --help
~~~
If you want to launch a run-eval-print loop (REPL) environment, then command:
~~~text
stack repl
~~~
!!! info
`stack ghci` can be used instead of `stack repl`. GHCi is GHC's REPL tool.
People organise Haskell code into packages. If you want to use Stack to install
an executable provided by a Haskell package, then all you have to do is command:
~~~text
stack install <package-name>
~~~
### Step 2: Next steps
The `stack new my-project` command in step one should have created the following
files and directories (among others):
~~~text
.
├── app
│ └── Main.hs
├── src
│ └── Lib.hs
├── test
│ └── Spec.hs
├── my-project.cabal
├── package.yaml
└── stack.yaml
~~~
The Haskell source code for the executable (application) is in file `Main.hs`.
The executable uses a library. Its source code is in file `Lib.hs`.
The contents of `my-project.cabal` describes the project's package. That file is
generated by the contents of `package.yaml`.
!!! info
If you want, you can delete the `package.yaml` file and update the
`my-project.cabal` file directly. Stack will then use that file.
The contents of `stack.yaml` describe Stack's own project-level configuration.
You can edit the source files in the `src` directory (used for the library) or
the `app` directory (used for the executable (application)).
As your project develops, you may need to depend on a library provided by
another Haskell package. If you do, then add the name of that new package to the
file `package.yaml`, in its `dependencies:` section.
!!! info
When you use `stack build` again, Stack will use `package.yaml` to create an
updated `my-project.cabal` for you.
If Stack reports that the Stack configuration has no specified version for the
new package, then follow Stack's likely recommended action to add a specific
version of that package your project's `stack.yaml` file, in its `extra-deps:`
section.
That was a really fast introduction on how to start to code in Haskell using
Stack. If you want to go further, we highly recommend you read Stack's
introductory [user's guide](GUIDE.md).
## Complete guide to Stack
A complete [user's guide](GUIDE.md) to Stack is available, covering all of
the most common ways to use Stack. Terms used in Stack's documentation are also
explained in the [glossary](glossary.md).
## Why Stack?
Stack is a build tool for Haskell designed to answer the needs of Haskell users,
both new and experienced. It has a strong focus on reproducible build plans,
multi-package projects, and a consistent, easy-to-learn set of Stack commands.
It also aims to provide the customizability and power that experienced
developers need.
Stack does not stand alone. It is built on the great work provided by:
* The __Glasgow Haskell Compiler__ ([GHC](https://www.haskell.org/ghc/)), the
premier Haskell compiler. Stack will manage your GHC installations and
automatically select the appropriate version of GHC for your project.
* The __Cabal build system__. Cabal is a specification for defining Haskell
packages and a [library](https://hackage.haskell.org/package/Cabal) for
performing builds.
!!! info
Cabal is also the name of another build tool, provided by the
`cabal-install` package. This guide distinguishes between them by Cabal
(the library) and Cabal (the tool).
* The __Hackage Haskell Package Repository__, a
[repository](https://hackage.haskell.org/) of Haskell packages providing
thousands of open source libraries and applications to help you get your work
done.
* The __Stackage package collection__, sets of packages from Hackage that are
[curated](https://www.stackage.org/). That is, they are regularly tested for
compatibility. Stack defaults to using Stackage package sets to avoid
problems with incompatible dependencies.
Stack is provided by a team of volunteers and companies under the auspices of
the [Commercial Haskell](http://commercialhaskell.com/) group. The project was
spearheaded by [FP Complete](https://www.fpcomplete.com/) to answer the needs of
commercial Haskell users. It has since become a thriving open source project
meeting the needs of Haskell users of all stripes.
If you'd like to get involved with Stack, check out the
[newcomer friendly](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3a%22newcomer+friendly%22)
label on the GitHub issue tracker.
## Questions, feedback, and discussion
* For answers to frequently asked questions about Stack, please see the
[FAQ](faq.md).
* For general questions, comments, feedback and support, please post to the
[Haskell Community](https://discourse.haskell.org/about).
* For bugs, issues, or requests, please
[open an issue](https://github.com/commercialhaskell/stack/issues/new).
* When using Stack Overflow, please use the
[haskell-stack](http://stackoverflow.com/questions/tagged/haskell-stack) tag.
## How to contribute to the maintenance or development of Stack
A [guide](CONTRIBUTING.md) is provided to help potential contributors to the
Stack project.
If you have already installed a version of Stack and the
[Git application](https://git-scm.com/) the followings steps should get you
started with building Stack from source with Stack:
1. Clone the `stack` repository from GitHub with the command:
~~~text
git clone https://github.com/commercialhaskell/stack.git
~~~
2. Change the current working directory to the cloned `stack` directory with
the command:
~~~text
cd stack
~~~
3. Build the `stack` executable using a preexisting installation of Stack with
the command:
~~~text
stack build
~~~
4. Once the `stack` executable has been built, check its version with the
command:
~~~text
stack exec -- stack --version
~~~
Make sure the version is the latest one.
5. In the GitHub repository's issue tracker, look for issues tagged with
[newcomer friendly](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3a%22newcomer+friendly%22)
and
[awaiting pull request](https://github.com/commercialhaskell/stack/issues?q=is%3Aopen+is%3Aissue+label%3A%22awaiting+pull+request%22)
labels.
If you need to check your changes quickly command:
~~~text
stack repl
~~~
and then, at the REPL's prompt, command:
~~~text
:main --stack-root=<path_to_root> --stack-yaml=<path_to_stack.yaml> <COMMAND>
~~~
This allows you to set a special Stack root (instead of the default Stack root)
and to target your commands at a particular `stack.yaml` file instead of the one
found in the current directory.
## How to uninstall
To uninstall Stack, it should be sufficient to delete:
1. the Stack root directory (see `stack path --stack-root`, before you
uninstall);
2. if different, the directory containing Stack's global YAML configuration file
(see `stack path --global-config`, before you uninstall);
3. on Windows, the directory containing Stack's tools (see
`stack path --programs`, before you uninstall), which is located outside of
the Stack root directory; and
4. the `stack` executable file (see `which stack`, on Unix-like operating
systems, or `where.exe stack`, on Windows).
You may also want to delete ``.stack-work`` directories in any Haskell projects
that you have built using Stack. The `stack uninstall` command provides
information about how to uninstall Stack.
|