How to declare circular dependent abstract classes in F #

Consider two abstract classes alpha and beta:

[<AbstractClass>]  
type alpha () =
    abstract member foo: beta->beta

[<AbstractClass>] 
and beta () = //***
    abstract member bar: alpha

If I try to compile that I am getting an error message, in the line indicated by * * *:

error FS0010: Unexpected keyword 'and' in interaction

And if I write:

[<AbstractClass>]  
type alpha () =
    abstract member foo: beta->beta

and beta () =
    abstract member bar: alpha

then I get:

error FS0365: No implementation was given for 'abstract member beta.bar : alpha'

and a hint that I should add the AbstractClass attribute

So how do I declare cyclically defined abstract classes?

+5
source share
1 answer

Place the attribute after the keyword 'and':

[<AbstractClass>]
type alpha () =
    abstract member foo : beta -> beta

and [<AbstractClass>]  beta () =
    abstract member bar : alpha
+7
source

All Articles