Stack project templates and GHC warnings

The simple Stack-supplied Stack project templates (with the exception of chrisdone, which sets -Wall), including the default new-template, do not set GHC flags for warnings. It has been suggested here that they should. I would like to canvas opinion: do people agree and, if they do, what flags should be set?

This 2018 article - Enable All The Warnings - advocates:

- -Weverything
- -Wno-missing-exported-signatures
- -Wno-missing-import-lists
- -Wno-missed-specialisations
- -Wno-all-missed-specialisations
- -Wno-unsafe
- -Wno-safe
- -Wno-missing-local-signatures
- -Wno-monomorphism-restriction

Would that be sensible in a default template in 2022? If not, what would be a better approach?

3 Likes

I use

-Wall
-Wcompat
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wredundant-constraints

based on an old lexi-lambda blog. Not as extreme as your list, and covers what you should care about.

1 Like

I think -Wall++ vs -Weveryting-- depends a bit on how the templates actually work. Do you expect that people will use newer compiler versions or do you update these lists for every compiler version? If you always update for each new compiler version then either approach works. However, if you expect these templates to work for future GHC releases I would recommend using the -Wall++ approach, because I think the “writing a book” example applies:

For example, if you’re writing a book, then you could plausibly expect readers to use a newer compiler than what you used when you wrote the book. If those users were using -Weverything, they might be confused by that your book’s sample code generates warnings.

In summary, I think the blog post makes a good argument for choosing -Weverything-- for your own projects, but if you are making a list for others (like when writing a book or a project template) then I’d stick to -Wall++.

I would in addition to @tonyday567’s suggestions enable some more extensions from -Weverything, however. In particular:

  • -Wpartial-fields
  • -Wmissing-home-modules
  • -Widentities
  • -Wmissing-export-lists
2 Likes

Thank you for your suggestions. I have now implemented:

-Wall
-Wcompat
-Widentities
-Wincomplete-record-updates
-Wincomplete-uni-patterns
-Wmissing-export-lists
-Wmissing-home-modules
-Wpartial-fields
-Wredundant-constraints
3 Likes