Skip to content

Confusing errors for polymorphic update with OverloadedRecordUpdate

I built ghc 9.2.0.20210422 and decided to see the error quality for OverloadedRecordUpdate.

Trying to load some silly modules:

{-# LANGUAGE OverloadedRecordUpdate, OverloadedRecordDot #-}

data Foo a = Foo { a :: a }
x = Foo ()
y = x{a.a=x}

Errors:

/tmp/a.hs:5:5: error:
    RebindableSyntax is required if OverloadedRecordUpdate is enabled.
  |
5 | y = x{a.a=x}
  |     ^^^^^^^^

OK, adding RebindableSyntax:

{-# LANGUAGE RebindableSyntax, OverloadedRecordUpdate, OverloadedRecordDot #-}

data Foo a = Foo { a :: a }
x = Foo ()
y = x{a.a=x}

Errors:

/tmp/a.hs:5:5: error: Not in scope: ‘setField’
  |
5 | y = x{a.a=x}
  |     ^^^^^^^^

/tmp/a.hs:5:5: error: Not in scope: ‘getField’
  |
5 | y = x{a.a=x}
  |     ^^^^^^^^

OK, adding imports:

{-# LANGUAGE RebindableSyntax, OverloadedRecordUpdate, OverloadedRecordDot #-}

import GHC.Records

data Foo a = Foo { a :: a }
x = Foo ()
y = x{a.a=x}

Errors:

/tmp/a.hs:7:5: error:
    Not in scope: ‘setField’
    Perhaps you meant ‘getField’ (imported from GHC.Records)
  |
7 | y = x{a.a=x}
  |     ^^^^^^^^
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information