RecordWildCards undocumented behavior
Summary
https://downloads.haskell.org/ghc/latest/docs/html/users_guide/exts/record_wildcards.html
There are two behaviors of RecordWildCards (RWC) undocumented or documented unclearly.
1. Unclear qualified names
For both pattern and expression wildcards, the “
..” expands to the missing in-scope record fields...The record field
fis in scope somehow (either qualified or unqualified).module M where data R = R { a,b,c :: Int } module X where import M( R(R,a,c) ) f a b = R { .. }The
R{..}expands toR{a=a}
There should be an example of qualified in-scope presence, which I find very useful
module M where
data R = R{a, b, c :: Int}
module X where
import M (R (R))
import M qualified
f a b = R{..}
The R{..} expands to R{M.a = a, M.b = b}, so you can use fields without messing with getters.
2. RWC interferes with NamedFieldPuns
With NamedFieldPuns (NFP) enabled and RWC disabled:
import M (R (R))
import M qualified
f foo = R{foo} -- use of NFP syntax, not RWC
error:
Not in scope: ‘foo’
Perhaps you want to add ‘foo’ to the import list in the import of
With RWC additionally enabled, the same code is compiled successfully!
So, RWC desugars NFP syntax R{foo} to R{M.foo = foo}, which must be documented.
Proposed improvements or changes
I'm not sure about specific wording.
Environment
- GHC version used: 8.10.4