70 %
Chris Biscardi

Reproducible Tutorials with Stack

Stack yields some nice benefits for blogging, tutorials, and more. The main benefit I want to talk about today is reproducibility when using stack to start a new project (in a tutorial).

Resolvers

To ensure repeatable resolutions, choose a specific resolver. Since even the nightlies get unique identifiers, we can ensure that any future attempt at reproducing a given tutorial is more likely to be successful.

Templates

Stack can use templates from github. Pointing to a specific template, whether custom or from the stack-templates repo, is good as well. Cloning git repos could be used as an alternative here, but one advantage of using Stack's support is that you can now have a single repo of templates and point to a specific git commit/file.

Code

A fully qualified reproducible template commmand could look like:

bash
stack new servant-users \
https://raw.githubusercontent.com/commercialhaskell/stack-templates/9a18e8762b8f048d403dabe5c19552ceb5292318/servant.hsfiles \
--resolver nightly-2016-04-10

-- note

Effectively, doing this is trying to freeze the (Hackage) world at a specific point in time for a specific .cabal setup. I'd argue that doing this is more useful (for tutorials) than trying to make sure a tutorial compiles with any arbitrary future set of packages.