6

Is there a way to automatically find unused functions (and constants) in a module or .hs file? Specifically, I mean those functions that are not used (directly or indirectly) by the functions in the export list of the current module/file.

I know that e.g. Emacs haskell mode has the ability to warn about unused importS as follows: The import of XXX is redundant

Is there similar tool or method for finding unused functions?

Note: I know this can be done manually by deleting some code and see whether it still compiles. But it's tedious process.

til
  • 205
  • 2
  • 5
  • Somewhat related: https://stackoverflow.com/questions/25649143/how-to-enable-dead-code-warnings-in-haskell-ghc?rq=1 https://stackoverflow.com/questions/18409508/dead-code-and-or-how-to-generate-a-cross-reference-from-haskell-source?rq=1 – Thilo Aug 07 '17 at 00:41
  • Another related post: https://stackoverflow.com/questions/18409508/dead-code-and-or-how-to-generate-a-cross-reference-from-haskell-source – snibbets Aug 07 '17 at 00:47
  • You might want to try [ghc-mod](https://github.com/DanielG/ghc-mod/wiki/Frontend) – wizzup Aug 07 '17 at 02:15

1 Answers1

7

Here are some relevant ghc -W flags:

-Wunused-binds
-Wunused-do-bind
-Wunused-foralls
-Wunused-imports
-Wunused-local-binds
-Wunused-matches
-Wunused-pattern-binds
-Wunused-top-binds
-Wunused-type-patterns

Or just use -Wall. You can get a complete list of ghc flags with ghc --show-options.

ErikR
  • 51,541
  • 9
  • 73
  • 124