Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Finding unused Haskell functions in a module or file?

Tags:

haskell

ghc

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.

like image 264
til Avatar asked Aug 07 '17 00:08

til


1 Answers

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.

like image 179
ErikR Avatar answered Sep 28 '22 00:09

ErikR