Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I selectively remove .cabal file's `ghc-options` in particular files?

Tags:

haskell

I am using

ghc-options: -Wall

in my .cabal file, and love it....

....except when I hate it. For instance, I have a Constants.hs file that looks like this

numDogs=1000
numCats=2000
......
....etc for like 100 lines

....and of course -Wall complains that I don't give all my types signatures, but changing the file to this

numDogs::Int
numDogs=1000

numCats::Int
numCats=2000

....etc

really would be stupid.

So, is there a way to turn off ghc-opts on a per file basis.

(I know that I can just leave out the ghc-options from cabal, and put it in each file that I want it in using {-# OPTIONS_GHC -Wall #-}, but when I do that, I often forget files altogether, so I'd rather not do it this way)

like image 278
jamshidh Avatar asked Oct 26 '25 15:10

jamshidh


2 Answers

Well, {-# OPTIONS_GHC flag #-} can take any GHC flag, so you can simply use -w to disable all warnings. But since you're mostly concerned about the missing signatures for constants, you probably want -fno-warn-missing-signatures and -fno-warn-type-defaults:

{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}

That being said, if you're using a bunch of constants with the same type, you can simply write:

numDogs, numCats, numParrots, numFishes, numRats :: Int

That also removes the warning, and makes sure that the constants have the appropriate type.

like image 81
Zeta Avatar answered Oct 29 '25 09:10

Zeta


Most of the flags implied by -Wall have an inversion -f-no-* option that if you apply locally will override the global setting. So for instance in a module that you want not to have toplevel signature you could add:

{-# OPTIONS_GHC  -fno-warn-missing-signatures #-}

And this will still endow your module with all the other checks implied by -Wall ( incomplete patterns and whatnot ) but just not missing signatures.

like image 36
Stephen Diehl Avatar answered Oct 29 '25 08:10

Stephen Diehl