【发布时间】:2020-11-09 04:44:52
【问题描述】:
(新手问题)。
我一直在努力使用 F# 中的选项更新嵌套记录。这是怎么做到的?
请假设:
module Visit =
type Model =
{
Id: int
Name: string
}
let initWithTime (t:DateTime) =
{
Id = 0
Name = sprintf "Time is %A" t
}
module Cell =
type Model =
{
Id: int
Visit: Visit.Model option
}
let setVisitFromInteger (i:int, m:Model) =
let appointmentTime =
DateTime.Today + TimeSpan.FromMinutes(float i)
{ m with Visit = { m.Visit
match m.Visit with
| Some x -> x with Name = sprintf "New appointment time %A" appointmentTime
| None -> Visit.initWithTime appointmentTime
}
}
显然,setVisitFromInteger 完全错误。如何正确更新嵌套的可选记录?
TIA
【问题讨论】:
标签: f#