F# forward type declarations

前端 未结 3 1260
终归单人心
终归单人心 2020-11-28 13:04

I stumbled across this problem in F#. Suppose, I want to declare two types that reference each other:


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


        
相关标签:
3条回答
  • 2020-11-28 13:55

    I figured it. It's:

    
    type firstType = 
         | T1 of secondType
         //................
    
    and secondType =
         | T1 of firstType  
         //................   
    
    0 讨论(0)
  • 2020-11-28 13:59

    You use 'and':

    type firstType = 
         | T1 of secondType
    
    and secondType =
         | T1 of firstType
    
    0 讨论(0)
  • 2020-11-28 14:04

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

    0 讨论(0)
提交回复
热议问题