Context
If I load the following into ghc-9.2.1-alpha2 which has support for RecordDotSyntax:
{-# LANGUAGE OverloadedRecordDot, OverloadedRecordUpdate, DuplicateRecordFields #-}
----------------------------------------------------------------------
data Point = Point { x :: Double, y :: Double }
instance Show Point where
show p = "Point { x = " ++ show p.x ++ ", y = " ++ show p.y ++ " }"
p = Point 10 20
I can then run the following in ghci:
ghci> p { x = 30 }
Point { x = 30.0, y = 20.0 }
Cool, it's working!
Issue
However, if I add the following to my test file above:
result =
let
a = Point 1 2
b = a { x = 3 }
in
b
and reload, I get the following message:
ghci> :r
[1 of 1] Compiling Main ( /home/dharmatech/tmp/test-ghc-9.2.0.20210422/point-update-issue.hs, interpreted )
/home/dharmatech/tmp/test-ghc-9.2.0.20210422/point-update-issue.hs:13:13: error:
RebindableSyntax is required if OverloadedRecordUpdate is enabled.
|
13 | b = a { x = 3 }
| ^^^^^^^^^^^
Failed, no modules loaded.
What I've tried
If I add RebindableSyntax as the message suggests, I get many more errors which look like this:
/home/dharmatech/tmp/test-ghc-9.2.0.20210422/point-update-issue.hs:3:27: error:
Not in scope: type constructor or class ‘Double’
|
3 | data Point = Point { x :: Double, y :: Double }
|
Question
Is there a way to get this to work? Or is it something that's just not implemented yet?
Update 2021-08-10
If I add the following as alias and Ari suggested:
import Prelude
import GHC.Records
I get the following:
point-update-issue.hs:17:13: error:
Not in scope: ‘setField’
Perhaps you meant ‘getField’ (imported from GHC.Records)
|
17 | b = a { x = 3 }
| ^^^^^^^^^^^
Failed, no modules loaded.