F#可选记录字段 [英] F# Optional Record Field

查看:49
本文介绍了F#可选记录字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个F#记录类型,并且希望其中一个字段是可选的:

I have a F# record type and want one of the fields to be optional:

type legComponents = {
    shares : int<share> ;
    price : float<dollar / share> ;
    totalInvestment : float<dollar> ;
}

type tradeLeg = {
    id : int ;
    tradeId : int ;
    legActivity : LegActivityType ;
    actedOn : DateTime ;
    estimates : legComponents ;
    ?actuals : legComponents ; 
}

在tradeLeg类型中,

我希望Actuals字段是可选的.我似乎无法弄清楚,也似乎无法在网络上找到可靠的例子.看来这应该很容易

in the tradeLeg type I would like the the actuals field to be optional. I can't seem to figure it out nor can I seem to find a reliable example on the web. It seem like this should be easy like

let ?t : int = None

但是我真的似乎无法使它正常工作. gh-谢谢

but I realy can't seem to get this to work. Ugh - thank you

T

推荐答案

Option怎么样?

type tradeLeg = {
    id : int option;
    tradeId : int option;
    legActivity : LegActivityType option;
    actedOn : DateTime option;
    estimates : legComponents option;
    actuals : legComponents option; 
}

这篇关于F#可选记录字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆