LoginSignup
0
0

More than 3 years have passed since last update.

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

Last updated at Posted at 2020-06-28
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})}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0