Detecting unused functions at build time in Haskell

Viewed 135

I'm trying to get the GHC to warn me whenever I write a new function and forget to use it anywhere. I've added the following function in my Main.hs:

unused :: () -> ()
unused _ = ()

and of course not used it.

I have the following in my *.cabal file:

 ghc-options: 
    -W
    -Wall
    -Werror
    -Wcompat
    -Wincomplete-uni-patterns
    -Wincomplete-record-updates
    -Wredundant-constraints
    -Wpartial-fields
    -Wunused-binds

I've specifically added -Wunused-binds to try to force the compiler to fail on this but it does not report any warning about an unused function.

Any idea what am I doing wrong here?

EDIT

Just to give a bigger picture, here is the beggining of the main file:


{-# LANGUAGE OverloadedStrings          #-}
{-# LANGUAGE DataKinds                  #-}
{-# LANGUAGE FlexibleContexts           #-}
{-# LANGUAGE FlexibleInstances          #-}
{-# LANGUAGE MultiParamTypeClasses      #-}
{-# LANGUAGE ScopedTypeVariables        #-}
{-# LANGUAGE TemplateHaskell            #-}
{-# LANGUAGE TypeApplications           #-}
{-# LANGUAGE TypeFamilies               #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Main where

import           Apecs
import           Linear                         ( V2(..) )
import           Control.Monad
import           Control.Monad.IO.Class
import           Control.Monad.Catch
import qualified System.Terminal               as T
import           System.Terminal.Internal
import qualified Data.Map                      as M
import           System.Random
1 Answers

Exporting only main function from module fixed the issue:

module Main(main) where

EDIT

Just for reference, this flag is already contained in -Wall so it would be enough to have this in cabal to catch it:

  ghc-options: 
    -Wall
    -Werror
Related