... | ... | @@ -14,10 +14,13 @@ I want to implement possibility to suppress particular kinds of warnings for par |
|
|
According to [\#602](https://gitlab.haskell.org//ghc/ghc/issues/602):
|
|
|
"One way to achieve this is to allow parts of a file to be delimited by pragmas specifying the warnings to be suppressed, and then filter out the warnings during compilation based on the source location attached to the warning."
|
|
|
|
|
|
|
|
|
For starting point i think, i would like to suppress warnings thrown by a single function. I think that suppressing warnings for bindings or particular expressions inside functions for example will ruin the readability of code. There is a nice example in [ Java](http://docs.oracle.com/javase/7/docs/api/java/lang/SuppressWarnings.html) of suppressing warnings for particular methods in classes.
|
|
|
|
|
|
## Use cases
|
|
|
|
|
|
|
|
|
For example you have a function in your source file that can perform some unsafe actions(unsafe I/O maybe). You think you are smarter than GHC, and you don't want to read such long warning's texts. So you wrap this piece of code in pragmas and compiler does not throw warnings and you are happy with that.
|
|
|
For example you have a function in your source file that can perform some unsafe actions(unsafe I/O maybe). You think you are smarter than GHC, and you don't want to read such long warning's texts. So you apply pragma to your function and compiler does not throw warnings and you are happy with that.
|
|
|
|
|
|
## Exempli gratia
|
|
|
|
... | ... | @@ -25,15 +28,22 @@ For example you have a function in your source file that can perform some unsafe |
|
|
I don't know conventions about naming pragmas, so let it be something like this.
|
|
|
|
|
|
```
|
|
|
{-# SUPPRESS_WARNINGS $warning_name$ #-}foo::IORefIntfoo= unsafePerformIO (newIORef 10)
|
|
|
{-# SUPPRESS #-}foo::IORefIntfoo= unsafePerformIO (newIORef 10)
|
|
|
```
|
|
|
|
|
|
|
|
|
We are suppressing warnings for one particular function
|
|
|
|
|
|
|
|
|
Or we can suppress warnings for some part of source code:
|
|
|
Or we can do this in top-level, i mean in the file header we can write and compiler will suppress warnings, that foo will throw, see [ this](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/pragmas.html) about WARNING and DEPRECATED pragmas
|
|
|
|
|
|
```
|
|
|
{-# SUPPRESS foo #-}--some code herefoo::IORefIntfoo= unsafePerformIO (newIORef 10)
|
|
|
```
|
|
|
|
|
|
|
|
|
Or as seen [ here](https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/pragmas.html) for INLINE pragma one can write
|
|
|
|
|
|
```
|
|
|
{-# SUPPRESS_WARNINGS $warning_names$ #-}foo::IORefIntfoo= unsafePerformIO (newIORef 10)bar::IORefIntbar= unsafePerformIO (newIORef 11)baz::IORefIntbaz= unsafePerformIO (newIORef 12){-# UNSUPPRESS_WARNINGS $warning_names$ #-}
|
|
|
foo::IORefIntfoo= unsafePerformIO (newIORef 10){-# SUPPRESS foo #-}
|
|
|
``` |
|
|
\ No newline at end of file |