【发布时间】:2021-11-25 03:55:18
【问题描述】:
我正在尝试在 F# 中编写一个带有一些基本参数验证的简单抽象类:
[<AbstractClass>]
type Record(recordType: int16) =
let recordType: int16 = recordType
do
if recordType < 0s then
invalidArg (nameof recordType)
但是,我在最后一行遇到错误:“this if expression is missing an else branch。”我尝试添加一个仅计算为 null 的 else 分支,但随后类型系统与我的代码不一致。难道我做错了什么?我应该使用其他方法来验证我的论点吗?
【问题讨论】:
标签: class validation constructor f# arguments