I have discovered that (in a different module to the one providing the type definition) a value can be updated using record syntax even if the data constructor is not exported, as long as the field name is exported.
That came as a surprise. I can’t see that is expressly discussed in the Haskell 2010 Language Report in Sections 5.2 (Export Lists) and Section 5.8 (Abstract Datatypes) or in Section 3.15.3 (Updates Using Field Labels).
In Section 3.15.3 it seems that the ‘translation’ of the x { f1 = 1}
example works, even if the translation would not be valid code because data constructors C1
and C2
are not available.
Should I have been surprised? Is this explained somewhere that is authoritative?