Allow record wildcards for empty records
Creating this as a tracking ticket for the implementation of https://github.com/ghc-proposals/ghc-proposals/pull/496, which is already accepted.
The idea is to allow
data Foo = Foo { }
f (Foo {..}) = 1
x = Foo {..}
for consistency with non-empty records. Other than aesthetic reasons, this is also practically useful for code generation - you can treat record matching with a wildcard the same way, regardless of how many fields the record being matched has.
Notably,
data Foo = Foo
f (Foo {..}) = 42
is also allowed, despite the inconsistency it causes with regards to having to now differentiate between n = 0
and n > 0
, where n
is the number of arguments the constructor Foo
has.
This seems to have been briefly discussed in the linked proposal.
To summarise, the new behaviour should be:
Only reject a wildcard when the constructor it's attached to is not a record and has at least one argument/field.
I'll be implementing this.
Implementation notes:
The error that's currently produced is GHC.Tc.Errors.Types.TcRnIllegalWildcardsInConstructor
.
The comment attached to it should be amended to reflect the new reality.
It's produced only in GHC.Rename.Pat.rnHsRecFields.rn_dotdot
. The check there needs to be amended to also find out if the constructor has non-record arguments.