我正在尝试为我正在做的项目创建 som 示例数据。为此,我需要一个简单的对象结构,其中对象包含一组对象。在这种情况下,可以保存评论的评论家。代码如下所示:
type Review =
{ MovieName: string;
Rating: double }
type Critic =
{ Name: string;
Ratings: Review[] }
let theReviews = [{ MovieName = "First Movie"; Rating = 5.5 }; { MovieName = "Second Movie"; Rating = 7.5 };]
let theCritic = { Name = "The Critic"; Ratings = [{ MovieName = "First Movie"; Rating = 5.5 }; { MovieName = "Second Movie"; Rating = 7.5 };] }
“评论”行工作正常,但我无法让“评论家”行工作。我得到的错误是:
错误 1 此表达式的类型应为 Review []
,但此处的类型为 'a list
我怎样才能让它工作?