gpt4 book ai didi

types - 如何在 F# 中定义两个相互依赖的类型?

转载 作者:行者123 更新时间:2023-12-02 08:36:27 24 4
gpt4 key购买 nike

<分区>

我是 F# 的新手所以请不要怪我:)

我的服务为我提供了用户、组和其他对象。用户对象如下所示:

{
"id": 0,
"firstname": null,
"lastame": null,
"emailaddress": null,
"active": false,
"groups": null,
"groupcount": 0,
"createdgroups": null,
"createdgroupscount": 0,
"createdfiles": null,
"createdfilescount": 0,
"createdfolders": null,
"createdfolderscount": 0,
"createdvideos": null,
"createdvideoscount": 0,
"createdcategories": null,
"createdcategoriescount": 0
}

组对象如下所示:

{
"id": 0,
"name": null,
"description": null,
"videos": null,
"videocount": 0,
"files": null,
"filecount": 0,
"members": null,
"membercount": 0,
"creator": {
"id": 0,
"firstname": null,
"lastame": null,
"emailaddress": null,
"active": false,
"groups": null,
"groupcount": 0,
"createdgroups": null,
"createdgroupscount": 0,
"createdfiles": null,
"createdfilescount": 0,
"createdfolders": null,
"createdfolderscount": 0,
"createdvideos": null,
"createdvideoscount": 0,
"createdcategories": null,
"createdcategoriescount": 0
}
}

现在我的问题是,creator 属性是 User 类型。 members 属性是一个用户列表。

这就是我的 F# 类型的样子,用户至上:

type User =
member this.ID = 0
member this.Firstname = ""
member this.Lastname = ""
member this.Emailaddress = ""
member this.Active = false

member this.AllGroupsCount = 0
member this.Groups = List<Group>.Empty

member this.AllCreatedGroupsCount = 0
member this.CreatedGroups = List<Group>.Empty

member this.AllCreatedFoldersCount = 0
member this.CreatedFolders = List<Folder>.Empty

member this.AllCreatedFilesCount = 0
member this.CreatedFiles = List<File>.Empty

member this.AllCreatedCategoriesCount = 0
member this.CreatedCategories = List<Category>.Empty

member this.AllCreatedVideosCount = 0
member this.CreatedVideos = List<Video>.Empty

这是组对象:

type Group =
member this.ID = 0
member this.Name = ""
member this.Description = ""
member this.Videos = List<Video>.Empty
member this.Files = List<File>.Empty
member this.Members = List<User>.Empty
member this.Creator = null

现在的问题是,当我将组放在用户对象之前时,组显示用户未定义,当我将用户放在组之前时,它显示组未定义,我该如何解决?

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com