在 OCaml 中更新匿名记录中的单个记录字段

问题描述 投票:0回答:1

这不是有效的语法,但是是否可以执行类似的操作来获取新的更新的匿名记录,类似于使用

with
处理普通记录?

type user = User {id: int, ... more fields}
let u = User {id = 1, ...}
let u2 = User with id = 2
ocaml record
1个回答
0
投票
20:01 < discocaml> <deepspacejohn> you can bind the record to a name with `let Thing t2 = t`
20:01 < discocaml> <deepspacejohn> `let t = Thing {id = 1} in let Thing t2 = t in Thing {t2 with id = 2}`
© www.soinside.com 2019 - 2024. All rights reserved.