Skip to content

feature: warn about unused data definitions (with typeclass instances)

Let's consider an example:

-- M.hs:
module M () where

-- ghc knows about uselessness of those
data D = D

-- but doesn't about this:
data E = E deriving (Show, Read)

ghc warns about useless D, but not E:

$ ghc-7.8.4 -Wall -c M.hs -fforce-recomp

M.hs:5:1: Warning:
    Defined but not used: type constructor or class ‘D’

M.hs:5:10: Warning: Defined but not used: data constructor ‘D’

There is no way to refer to E type outside or call it's unstances, correct?

I would expect no code should be generated for this module.

ghc could also warn about defined, but not used instances for types, that are not exported.

Some background on where those stray types come from:

  1. programmer usually adds a set of data types into their program

(say, 10-15 types to represent an AST)

  1. then annotates them with 'deriving (Read, Show)' convenience instances
  2. (months later) amends AST representation a bit and leaves

leftover data types not used anywhere

Does that make sense?

Thanks!

Trac metadata
Trac field Value
Version 7.8.4
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information