[GHC] #15855: Warn about incomplete NamedFieldPuns patterns
GHC
ghc-devs at haskell.org
Sat Nov 3 15:01:24 UTC 2018
#15855: Warn about incomplete NamedFieldPuns patterns
-------------------------------------+-------------------------------------
Reporter: Artyom.Kazak | Owner: (none)
Type: feature | Status: new
request |
Priority: normal | Milestone:
Component: Compiler | Version: 8.6.1
Keywords: | Operating System: Unknown/Multiple
Architecture: | Type of failure: None/Unknown
Unknown/Multiple |
Test Case: | Blocked By:
Blocking: | Related Tickets:
Differential Rev(s): | Wiki Page:
-------------------------------------+-------------------------------------
In certain situations it's nice to be able to ensure that record pattern
matches are exhaustive:
{{{#!haskell
data R = R {a, b :: Int}
-- should warn
f R{a} = a
-- should not warn
g R{a, b} = a + b
-- should not warn
h R{a, ..} = a + b
-- should not warn
i R{a, b = _} = a
}}}
It's useful when there are several functions that inspect a record (e.g.
handlers that update a subset of fields in a database) and we want to make
certain that when a new field is added to the record, the programmer won't
forget to update functions working with that record (either by handling
the field or explicitly discarding it). Currently the only non-hacky way
to do it is writing `f (R a _) = ...`, which is obviously not ideal.
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/15855>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list