Missing method in type class instance [GHC-06201]

Flag: -Wmissing-methods
Enabled by default

This warning means that a type class instance is missing some required method implementations.

Examples

No explicit implementation for method instance

Error Message

A.hs:7:10: warning: [GHC-06201] [-Wmissing-methods]
    • No explicit implementation for
        ‘multiply’
    • In the instance declaration for ‘Calculator Int’
  |
7 | instance Calculator Int where

Explanation

The type class Calculator requires you to implement two methods: add and multiply. However, the example instance instance Calculator Int only implements the method add and not multiply To fix this, implement the method multiply!

A.hs
Before
module A where

class Calculator a where
    add :: a -> a -> a
    multiply :: a -> a -> a

instance Calculator Int where
    add a b = a + b
After
module A where

class Calculator a where
    add :: a -> a -> a
    multiply :: a -> a -> a

instance Calculator Int where
    add a b = a + b
    multiply a b = a * b
No explicit implementation for method instance 2

Error Message

A.hs:8:10: warning: [GHC-06201] [-Wmissing-methods]
    • No explicit implementation for
        either ‘<*>’ or ‘liftA2’
    • In the instance declaration for ‘Applicative Box’
  |
8 | instance Applicative Box where
  |          ^^^^^^^^^^^^^^^

Explanation

The type class Applicative requires you to implement at least two methods:

  • pure, and
  • liftA2 or multiply (can also be both).

Such or constraints can be expressed via the {-# MINIMAL #-} pragma.

To fix this, either implement the method liftA2 or <*>. For this example, we implemented <*>, but either or both is fine, too.

A.hs
Before
module A where

data Box t = SomeBox t

instance Functor Box where
    fmap f (SomeBox a) = SomeBox (f a)

instance Applicative Box where
    pure a = SomeBox a
After
module A where

data Box t = SomeBox t

instance Functor Box where
    fmap f (SomeBox a) = SomeBox (f a)

instance Applicative Box where
    pure a = SomeBox a
    SomeBox f <*> SomeBox a = SomeBox (f a)