Skip to content

GHC doesn't warn about missing implementations for class methods beginning with an underscore

This code compiles without any warnings!

{-# OPTIONS_GHC -Wmissing-methods #-}
module Bug where

class Foo a where
  _Bar :: a -> Int

instance Foo Int

This code, however, //does// emit a warning:

{-# OPTIONS_GHC -Wmissing-methods #-}
module Warns where

class Foo a where
  bBar :: a -> Int

instance Foo Int
Warn.hs:7:10: warning: [-Wmissing-methods]
    • No explicit implementation for
        ‘bBar’
    • In the instance declaration for ‘Foo Int’

The only difference is in the name of the class method of Foo. Namely, when a class method is prefixed with an underscore, GHC seems to look the other way when checking if any instances are missing an implementation of it.

I'd argue that this behavior is incorrect, since I can't envision any scenario in which you'd want the compiler //not// to warn you about missing method implementations (as opposed to, say, not warning about an unused record selector).

Edited by Ryan Scott
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information