views:

345

answers:

3

Hello everybody,

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?

+12  A: 

You use 'and':

type firstType = 
     | T1 of secondType

and secondType =
     | T1 of firstType
Johan Kullbom
+4  A: 

I figured it. It's:


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

and secondType =
     | T1 of firstType  
     //................   
Max
you use the same notation for mutually recursive functions as well - in case you didn't already know that.
Massif
+1  A: 

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

toyvo