Data family instances shouldn't trigger unused type patterns
Summary
Data types definitions don't trigger unused type patterns when there is an unused type variable, yet data instances do, somewhat expectedly, trigger this.
See example below.
Steps to reproduce
{-# LANGUAGE GHC2021 #-}
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -Wunused-type-patterns #-}
import Data.Kind (Type)
data family D (f :: Type) :: Type -> Type
data MyConst (a :: Type)
newtype instance D (MyConst a) b = MyConst a
b
triggers the unused type pattern warning.
It is in one sense unused: it doesn't appear on the RHS,
yet in another sense, it is used. If we write _b
as the
warning wants, we get the following behaviour:
:t MyConst
MyConst :: a -> D (MyConst a) _b
Is _b
used here? If not, why does data Const a b = Const a
not
trigger the warning?
Expected behavior
I suggest either making the warning more lenient, or perhaps
adding a new warning.
I am not sure when someone would want the old behaviour.
The whole reason for why this is useful is that in function definitions,
an unused argument often means you forgot to account for something.
Marking it with a _
marks that you aren't supposed to use it.
This applies to type families too, but not to data families I would say:
If you forget to use a type variable, code that uses the instance will fail entirely
as the constructors are wrong, hence we don't need the warning.
Environment
- GHC version used: GHC 9.2.4