一部の値を変更したレコード

Database.Persist.MySQLの設定を調べていて、こんな記述を発見。

defaultConnectInfo :: ConnectInfo
Default information for setting up a connection.
(中略)
Use as in the following example:

connect defaultConnectInfo { connectHost = "db.example.com" }
Database.Persist.MySQL

レコードってこんな使い方できたっけ?
ということで、試しにいろいろやってみた。

  • Hoge.hs
data Hoge = Hoge { hoge :: Int, piyo :: String } 
 deriving Show

で、

> :l Hoge.hs
[1 of 1] Compiling Main             ( Hoge.hs, interpreted )
Ok, modules loaded: Main.

> let aa = Hoge { hoge = 9, piyo = "aaa" }
> aa
Hoge {hoge = 9, piyo = "aaa"}

> aa { hoge = 22 }
Hoge {hoge = 22, piyo = "aaa"}

> aa { piyo = "xx" }
Hoge {hoge = 9, piyo = "xx"}

> aa
Hoge {hoge = 9, piyo = "aaa"}

> aa { piyo = "xx" } { hoge = 0 }
Hoge {hoge = 0, piyo = "xx"}

> aa { piyo = "xx" } { hoge = 0 } { piyo = "uuu" }
Hoge {hoge = 0, piyo = "uuu"}

> hoge aa
9

> hoge aa { piyo = "xx" } { hoge = 0 } { piyo = "uuu" }
0

へ〜。