Types 在F中声明内部类型#

Types 在F中声明内部类型#,types,f#,Types,F#,最近我遇到了一个代码列表,如下所示: type MyType = | MyType of int and internal MyInternal = | One of MyType | Two of MyType 我不熟悉“and internal”(第三行)的用法,我想知道这样使用“type internal”是否有什么区别: type MyType = | MyType of int type internal MyInternal = | One of MyTyp

最近我遇到了一个代码列表,如下所示:

type MyType =
  | MyType of int

and internal MyInternal =
  | One of MyType
  | Two of MyType
我不熟悉“and internal”(第三行)的用法,我想知道这样使用“type internal”是否有什么区别:

type MyType =
  | MyType of int

type internal MyInternal =
  | One of MyType
  | Two of MyType

我对这两种形式都做了短暂的实验,我看不出有什么不同。这仅仅是两种不同的方式来编写相同的东西吗?

不,您建议的代码肯定更惯用

type T = ...
and U = ...
通常仅当类型相互递归时才使用。将其与内部类型一起使用会更加奇怪,因为第一种类型的构造函数也需要内部化:

type T = internal | T of U
and internal U = | U of T

在本例中,
关键字将用于定义
MyType
MyInternal
。由于
MyType
MyInternal
不是相互递归的,因此不需要

正如MSDN页面所述:

and关键字替换除第一个关键字外的所有关键字上的type关键字 定义

因此,这些定义是等价的