6

Is there a way to put {-# LANGUAGE <feature> #-} pragmas in either the:

  • <project>.cabal, or
  • stack.yaml

file, to avoid repeating the same header code in every *.hs file of a project?

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
dbanas
  • 1,707
  • 14
  • 24
  • 8
    `default-extensions:` field in Cabal – user2407038 Jan 31 '18 at 00:23
  • 2
    @user2407038, I think any mention of that feature should probably also explain why many people (such as myself) are generally opposed. It makes it impossible to see from the text of each module which extensions are in play. That can be quite confusing! – dfeuer Jan 31 '18 at 18:43

2 Answers2

9

As @user2407038 said in the comments, you can use the default-extensions field in your <project>.cabal file.

If you wanted to have OverloadStrings and GADTs in all of your modules in the project, you would list it in relevant section of your cabal file (i.e. if you want it for all of your library files, put it in library).

For example:

-- <project>.cabal
...
library
  hs-source-dirs:       src
  default-extensions:   GADTs
                      , OverloadedStrings 
  ...

If you are using a package.yaml configuration file to generate your <project>.cabal file, you can also specify this field there.

-- package.yaml
library:
  source-dirs: src
  default-extensions:
    - OverloadedStrings
    - GADTs
  exposed-modules:
    - MyModule
  ...
jkeuhlen
  • 4,401
  • 23
  • 36
2

Wow this is annoying. The error message from cabal literally says to use 'extensions:', but you have to use 'default-extensions:'...

Adam Wall
  • 163
  • 8