F# forward type declarations

隐身守侯 提交于 2019-11-26 08:28:36

问题


I stumbled across this problem in 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?


回答1:


You use 'and':

type firstType = 
     | T1 of secondType

and secondType =
     | T1 of firstType



回答2:


I figured it. It's:


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

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



回答3:


The limitation is that the types have to be declared in the same file.



来源:https://stackoverflow.com/questions/1378575/f-forward-type-declarations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!