Ambiguous record update error message text
Suppose we have
data S = MkS { foo, bar, baz :: Int }
data T = MkT { foo, bar, baz :: Int }
blah x = x { foo = 1, bar = 2, baz = 3 }
GHC rightly errors, with
Scratch.hs:35:10: error:
* Record update is ambiguous, and requires a type signature
* In the expression: x {foo = 1, bar = 2, baz = 3}
In an equation for `blah': blah x = x {foo = 1, bar = 2, baz = 3}
|
35 | blah x = x { foo = 1, bar = 2, baz = 3 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
But, with the reduction in power of -XDuplicateRecordFields
coming soon, a type signature will be insufficient for disambiguating. Indeed, there is no good way to disambiguate this record update; the user will have to rewrite their code, likely to use a manual case
or something like it. (If the records were in different modules, module prefixes could also help.)
In https://github.com/haskell/error-messages/issues/57, @adamgundry and I came up with
Scratch.hs:35:10: error:
• Record update for fields 'foo', 'bar' and 'baz' is ambiguous,
because they all appear in types 'S' and 'T'.
* In the expression: x {foo = 1, bar = 2, baz = 3}
In an equation for `blah': blah x = x {foo = 1, bar = 2, baz = 3}
|
35 | blah x = x { foo = 1, bar = 2, baz = 3 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That would seem to be a nice little improvement, giving the user more information and not suggesting an ineffective fix.