f# - 如何解决联合案例之间的循环引用?

标签 f#

如何解决联合案例之间的循环引用?

type ModuleInfo = | Author of Name
                  | Section of Section
                  | Duration of Duration
                  | Url of string

我收到以下错误:

The type 'Section' is not defined.

代码如下:

module ManageModule.Entities

type FirstName = FirstName of string
type LastName = LastName of string

type Name = | First of FirstName
            | Last of LastName
            | Suffix of string option

type Duration = | Hours of int
                | Minutes of int
                | Seconds of int

type ModuleInfo = | Author of Name
                  | Section of Section
                  | Duration of Duration
                  | Url of string

type Module = Module of ModuleInfo
type Modules = Modules of ModuleInfo list

type Section = | Introduction of Module
               | Conclusion of Module

最佳答案

您可以使用关键字:

type ModuleInfo = 
  | Author of Name
  | Section of Section
  | Duration of Duration
  | Url of string

and Module = Module of ModuleInfo
and Modules = Modules of ModuleInfo list

and Section = 
  | Introduction of Module
  | Conclusion of Module

关于f# - 如何解决联合案例之间的循环引用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34706953/

相关文章:

c# - 在数学方面,F# 真的比 C# 好吗?

f# - F# 中 seq<int> 与 Lazy<LazyList<int>> 的性能

c# - 查找格式正确的括号的所有组合

c# - F# 编译器如何知道正在调用 C# 方法以及参数需要语法元组?

list - F#返回元组列表中中间值最大的3个元素元组

f# - 如何将第三方 dll 引用添加到 F# 项目?

f# - 简单的rec函数中的F#和内存泄漏

string - F#:从字符串中删除前 N 个字符?

.net - 这是 F# 结构化 printf 错误吗?

list - F#选择对随机整数列表进行排序