[ghc-steering-committee] #668: Allow reserved identifiers as fields in OverloadedRecordDot, recommendation: accept

Adam Gundry adam at well-typed.com
Tue Oct 29 20:12:03 UTC 2024


Dear Committee,

In the interests of getting things moving on proposal #668 from Matt 
Parsons, I'll shepherd it myself, and recommend we accept it.

https://github.com/ghc-proposals/ghc-proposals/pull/668

This is a small amendment to the OverloadedRecordDot extension to allow 
reserved identifiers as field names. For example, this program is 
currently rejected with a parse error, but would be accepted:

   import GHC.Records

   x = foo.type -- parse error, "type" is a reserved identifier

   data T = MkT Int
   foo = MkT 42
   instance HasField "type" T Int where
      getField (MkT x) = x

While "type" is not a valid field name in a traditional Haskell record 
data type, there is nothing stopping a user defining their own instance 
for `HasField "type" r a`, and some users would like to do so (e.g. when 
using HasField to interface with a database). Attempting to use such an 
instance with OverloadedRecordDot runs into this parse error. However 
the presence of the dot syntax means there is no ambiguity in what the 
user means. Even if a user wrote `x.type` by accident, they are likely 
to get better diagnostic information if the parser accepts the program. 
The only issue I see is that some syntax highlighters unaware of this 
change may incorrectly highlight such record projections as keywords.

Please indicate whether you are happy to accept this proposal.

Cheers,

Adam


-- 
Adam Gundry, Haskell Consultant
Well-Typed LLP, https://www.well-typed.com/

Registered in England & Wales, OC335890
27 Old Gloucester Street, London WC1N 3AX, England


More information about the ghc-steering-committee mailing list