简体   繁体   English

F#转发类型声明

[英]F# forward type declarations

I stumbled across this problem in F#. 我偶然发现了F#中的这个问题。 Suppose, I want to declare two types that reference each other: 假设,我想声明两种相互引用的类型:


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

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

How do I do that, so the compiler does not generate an error? 我该怎么做,所以编译器不会生成错误?

You use 'and': 你使用'和':

type firstType = 
     | T1 of secondType

and secondType =
     | T1 of firstType

I figured it. 我想通了。 It's: 它的:


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

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM