Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
Help us understand the problem. What is going on with this article?

ネストしたレコードの更新

maz = { name = "mazohho", point = { x = 10, y = 20 } }

この point を素朴に更新しようとしてもコンパイルエラーとなってしまう。

-- これはできない
new_maz = { maz | point = { maz.point | y = 2 }}

一度 let で一時変数に受けておくと問題ない。

-- これは大丈夫
new_maz = 
  let maz_point = maz.point
  in  { maz | point = { maz_point | y = 2 }}

-- こういう手もあるがわかりやすいとは言えない
new_maz = { maz | point = maz.point |> (\n -> { n | x = 2})}
hatena-corp
「知る」「つながる」「表現する」で新しい体験を提供し、人の生活を豊かにする
https://hatenacorp.jp/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away