Unused Record Wildcard [GHC-83475]
Flag: -Wunused-record-wildcards
Enabled by: -Wall
If RecordWildCards
is enabled we can automatically bind fields of a record by using patterns like MyRecord{..}
. Not using any of the record fields that were bound using the record wildcard syntax will result in a warning.
Examples
Pattern contains unused record wildcard
None of the fields bound by Foo{..}
are used in f
, so the pattern may be safely removed.
Warning
GHC-83475/example1/before/Example1.hs:7:7: warning: [-Wunused-record-wildcards]
No variables bound in the record wildcard match are used
Possible fix: omit the โ..โ
|
7 | f Foo{..} = "Hello"
| ^^
Example1.hs
Before
{-# OPTIONS_GHC -fwarn-unused-record-wildcards #-}
{-# LANGUAGE RecordWildCards #-}
module Example1 where
data Foo = Foo { x :: Int, y :: Int, name :: String }
f :: Foo -> String
f Foo{..} = "Hello"
After
{-# OPTIONS_GHC -fwarn-unused-record-wildcards #-}
{-# LANGUAGE RecordWildCards #-}
module Example1 where
data Foo = Foo { x :: Int, y :: Int, name :: String }
f :: Foo -> String
f Foo{} = "Hello"