我有这个记录:
type Client =
{ Name : string; Income : int ; YearsInJob : int
UsesCreditCard : bool; CriminalRecord : bool }
要为此记录创建生成器,我尝试了以下代码:
let chooseFromList xs =
gen {
let! idx = Gen.choose(0, List.length xs - 1)
return (List.nth xs idx)
}
let generateName = (Gen.oneof [ gen {return "A"};gen {return "B"};gen {return "C"}])
let generateIncome= (chooseFromList [0..5000])
let generate_YearsInJob= chooseFromList [0..45]
let generate_UsesCreditCard = (Gen.oneof [ gen { return true }; gen { return false } ])
let generate_UsesCriminalRecord= (Gen.oneof [ gen { return true }; gen { return false } ])
let genertate_Client =
{
Name= generateName;
Income=generateIncome;
YearsInJob=generate_YearsInJob
UsesCreditCard=generate_UsesCreditCard
CriminalRecord=generate_UsesCriminalRecord
}
问题Name= generateName;
与我遇到的错误一致:
This expression was expected to have type string,but here has type Gen<string>
最后剩余的行存在此错误。