有没有办法在 F# 中调用 F# 记录类型的构造函数?
我的动机是我一直在使用 FSharpx 的应用验证,但发现自己编写了许多只构建记录的样板函数。
buildAddress 函数例如在简单的样板中,如果可能的话,我很想摆脱它。
let buildAddress streetNumber streetLine1 streetLine2 suburb state postcode =
{
Address.StreetNumber = streetNumber
StreetLine1 = streetLine1
StreetLine2 = streetLine2
Suburb = suburb
State = state
Postcode = postcode
}
let validateAddress streetNumber streetLine1 streetLine2 suburb state postcode =
buildAddress
<!> isNumber streetNumber
<*> Success streetLine1
<*> Success streetLine2
<*> Success suburb
<*> Success state
<*> validatePostcode postcode