Incorrect documentation about ambiguous record updates?
Summary
The documentation for DuplicateRecordFields
says
As of GHC 9.4.1, ... for record updates, there must be at most one datatype that has all the field names being updated.
Am I misunderstanding what this means, or is it incorrect? For example, this program works, yet there is more than one datatype that has all the field names being updated (just field
):
{-# LANGUAGE DuplicateRecordFields #-}
data A = A { field :: Int }
data B = B { field :: Int }
fun :: A -> A
fun a = a { field = 0 }
I think the text may be referring to the proposal "DuplicateRecordFields without ambiguous field access", but that proposal is not yet enacted. So far its only function is to give a warning on code that will no longer work at some unspecified point in the future. For example, the code above yields the warning
test28.hs:8:13: warning: [GHC-02256] [-Wambiguous-fields]
Ambiguous record update with parent type constructor ‘A’.
This type-directed disambiguation mechanism will not be supported by -XDuplicateRecordFields in future releases of GHC.
Consider disambiguating using module qualification instead.
|
8 | fun a = a { field = 0 }
| ^^^^^^^^^
So perhaps the documentation should say something like
In some future GHC, for record updates, there must be at most one datatype that has all the field names being updated. The alternative will be to use
OverloadedRecordUpdate
.
cc @adamgundry