5

Consider the 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 get an error, on the line indicated with * * *:

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 the hint that I should add the AbstractClass Attribute

So how do i declare circularly defined abstract classes?

qehgt
  • 2,972
  • 1
  • 22
  • 36
Frames Catherine White
  • 27,368
  • 21
  • 87
  • 137

1 Answers1

7

Put the attribute after the 'and' keyword:

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

and [<AbstractClass>]  beta () =
    abstract member bar : alpha
Ramon Snir
  • 7,520
  • 3
  • 43
  • 61
Brian
  • 117,631
  • 17
  • 236
  • 300