liveBook · Manning

Stack

As explained in Learn Haskell by Example

stack is a build tool and project-management toolchain for Haskell projects.

stack is a build tool and project-management toolchain for Haskell projects. Running `stack new caesar` creates a ready-to-use project directory with configuration, application, library, and test areas. section 2.1.2

A new stack project separates responsibilities:

  • `app` contains executable entry points such as `Main.hs`. section 2.1.2
  • `src` contains reusable library modules, types, and functions; `Lib.hs` is the initial working file. section 2.1.2
  • `test` holds test suites, while `stack.yaml`, `package.yaml`, and the Cabal file configure dependencies and compilation. section 2.1.2
Listing 2.1 The project structure for a new stack project
caesar
├── CHANGELOG.md
├── LICENSE
├── README.md
├── Setup.hs
├── app              #1
│     └── Main.hs
├── caesar.cabal
├── package.yaml
├── src     #2
│     └── Lib.hs
├── stack.yaml
└── test        #3
       └── Spec.hs

Inspect the generated project tree, including application, library, test, and configuration files. section 2.1.2

Use `stack repl` to enter GHCi from a stack project; its modules and definitions load automatically. Use `stack run` to build and execute the project. Place a single `--` before arguments intended for the executable, as in `stack run -- Testpath`. section 2.1.2 section 3.4.2

stack run <arguments for stack> -- <arguments for the program>

Use the command pattern to distinguish stack options from arguments passed to the program. section 3.4.2

How Learn Haskell by Example covers it

How deep it goes
Explains project structure and essential commands, but defers dependency editing and detailed testing.
Examples
Uses Caesar and line-numbering projects, `stack new caesar`, `stack repl`, and `stack run -- Testpath`.
What it assumes
Assumes stack is installed and a command-line environment is available, while introducing project organization from the beginning.
What you can do after
Build it from scratch, explore it interactively, and run its executable with command-line arguments.
How it connects
Connects Haskell projects with GHCi, Cabal configuration, executables, libraries, and test suites.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn Haskell by Example. The section links point to the parts of the book it draws on.