2

Possibly a dumb question:

The Stack documentation mentions package.yaml as the right place to add dependencies, but all I see in my project directory is a single stack.yaml file; is that the right place, then?

(I see an existing question that asks about redundancy between these two files, but I don't even see the package.yaml file at all !!)

If it helps:

$ stack --version
Version 1.9.3, Git revision 40cf7b37526b86d1676da82167ea8758a854953b (6211 commits) x86_64 hpack-0.31.1
duplode
  • 33,731
  • 7
  • 79
  • 150
agam
  • 5,064
  • 6
  • 31
  • 37

3 Answers3

6

package.yaml is actually processed by hpack; it's not a stack feature, except in so far as if it sees one there in your project it'll use it and generate a .cabal file.

You can create a package.yaml yourself from scratch. You don't need to do stack new or whatever.

I certainly find it using package.yaml rather than project.cabal convenient. There's no nice user guide, as such (as pointed out in the hpack README) but a few examples and you'll realize there's not much to it:

I have seen a few mentions that the Cabal library now supports new features to reduce the tedious repetition (perhaps in a >= 2.x format?) which might make the need for package.yaml go away fairly soon, which would be fine.

Andrew Cowie
  • 100
  • 7
3

Usually package.yaml is the correct place to add dependencies, and stack.yaml is the correct place to add additional information about those dependencies.

If you're just using packages from the project's main stack snapshot and using the default build settings for all of them: you generally don't need to edit stack.yaml at all. Dependencies are mentioned in stack.yaml when:

  • The package isn't in a stack snapshot
  • You need a different version of the package from the one your stack snapshot provides
  • The package (or the specific version you need) isn't on hackage at all (for example: you need stack to get it from github)
  • You need the package to be compiled with non-default flags
  • etc
Jeremy List
  • 1,756
  • 9
  • 16
1

Nevermind, it turns out I had run stack new <project> simple; if I had run stack new <project> new-project, it would have generated the package.yaml file instead of the <project>.cabal file I currently find there.

agam
  • 5,064
  • 6
  • 31
  • 37