Real World Haskell says "Haskell compiler can warn us if we introduce a variable name in a pattern, but do not use it in a function's body".
I often forget to use variables which I bind, so I want to use this feature. But my ghci and ghc seem to be fine with unused variables, and I actually have never seen this since I started learning Haskell a few months ago.
How can I use this feature? Or Haskell compiler does not have this feature anymore?
As said before, the option is -fwarn-unused-binds
or -Wall
for all warnings. Another one is -Werror
to make the warnings stop the compilation.
To use them, you pass them to ghc
or ghci
on the command-line. Additionally, during a session in ghci, you can type
:set -fwarn-unused-binds
With cabal
you can add ghc-options
to the executable section. For instance :
executable my-program
main-is: MyProgram.hs
hs-source-dirs: src
ghc-options: -Wall
Now, running cabal configure && cabal build
(and other commands) will use the -Wall
option.
You can look at Warnings. I generally use -Wall
in my projects which shows unused binded variables along with several other useful warnings. There is specific flag (-fwarn-unused-binds
) too to do just what you want.
You can add the -fwarn-unused-binds
flag to ghc
or ghci
. To enable other useful warnings, use -W
. To enable all warnings, use -Wall
. For example:
ghci -fwarn-unused-binds
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With