27

I often have similar properties in many stanzas of my .cabal files. E.g.

Library x
    ...
    ghc-options:
       -O2 -Wall -fno-warn-missing-signatures -fwarn-incomplete-patterns
       -fno-warn-name-shadowing

Executable y
    ...
    ghc-options:
       -O2 -Wall -fno-warn-missing-signatures -fwarn-incomplete-patterns
       -fno-warn-name-shadowing

Keeping them consistent is tedious and error-prone. Is there a better way?

Even trickier is when the fields are similar but not exactly the same e.g. when I have several executables which have common build dependencies but small variations.

Ajoy
  • 1,838
  • 3
  • 30
  • 57
daf
  • 5,085
  • 4
  • 31
  • 34
  • 2
    I don't think there's currently any good solution. Two options to bypass this problem in parts are: (A) use multiple `ghc-options` fields per component (yes, that's possible), thereby making the shared options completely identical and the differences easier to maintain; and (B) generate your Cabal file from some other source that does not contain redundant information. – kosmikus Mar 03 '13 at 11:10
  • Possible duplicate of [How to reduce duplication in the build-depends fields of a .cabal file?](https://stackoverflow.com/questions/10163604/how-to-reduce-duplication-in-the-build-depends-fields-of-a-cabal-file) – phadej Sep 20 '18 at 16:54
  • See https://stackoverflow.com/questions/10163604/how-to-reduce-duplication-in-the-build-depends-fields-of-a-cabal-file – phadej Sep 20 '18 at 16:54

2 Answers2

2

I think that cabal does not provide that functionality. I've also wondered about this some time ago. You can see my comment on Johan Tibell's blog as well as Johan's answer to it.

Jan Stolarek
  • 1,409
  • 1
  • 11
  • 21
1

I have written a tool to make it easier to specify Cabal files in Haskell, which helps deal with this issue and a few others.

https://hackage.haskell.org/package/cartel

massysett
  • 1,100
  • 6
  • 13