Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/fsharp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Syntax F#转发类型声明_Syntax_F#_Recursion_Types_Mutual Recursion - Fatal编程技术网

Syntax F#转发类型声明

Syntax F#转发类型声明,syntax,f#,recursion,types,mutual-recursion,Syntax,F#,Recursion,Types,Mutual Recursion,我在F#中偶然发现了这个问题。假设我想声明两种相互引用的类型: type firstType = | T1 of secondType //................ type secondType = | T1 of firstType //................ 如何做到这一点,使编译器不会生成错误?您使用“and”: type firstType = | T1 of secondType and se

我在F#中偶然发现了这个问题。假设我想声明两种相互引用的类型:


type firstType = 
     | T1 of secondType
     //................

type secondType =
     | T1 of firstType  
     //................    
如何做到这一点,使编译器不会生成错误?

您使用“and”:

type firstType = 
     | T1 of secondType

and secondType =
     | T1 of firstType
我猜到了。它是:


type firstType = 
     | T1 of secondType
     //................

and secondType =
     | T1 of firstType  
     //................   

限制是类型必须在同一个文件中声明。

请参见,对于相互递归函数,您也使用相同的表示法-以防您还不知道这一点。每次我觉得F#中有些东西不优雅时,我都会惊喜地发现有一个优雅的解决方案。