Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I declare circular dependant abstract Classes in F#

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?

like image 530
Lyndon White Avatar asked May 06 '12 04:05

Lyndon White


People also ask

How do we declare an abstract class?

You create an abstract class by declaring at least one pure virtual member function. That's a virtual function declared by using the pure specifier ( = 0 ) syntax. Classes derived from the abstract class must implement the pure virtual function or they, too, are abstract classes.

Can we declare object of abstract class?

No, we can't create an object of an abstract class. But we can create a reference variable of an abstract class. The reference variable is used to refer to the objects of derived classes (subclasses of abstract class).

How do you call an abstract class method in Java?

A method which does not have body is known as abstract method. It contains only method signature with a semi colon and, an abstract keyword before it. public abstract myMethod(); To use an abstract method, you need to inherit it by extending its class and provide implementation to it.

Which of the following declares an abstract method in an abstract Java class?

An abstract method in Java is declared through the keyword “abstract”.


1 Answers

Put the attribute after the 'and' keyword:

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

and [<AbstractClass>]  beta () =
    abstract member bar : alpha
like image 199
Brian Avatar answered Sep 22 '22 15:09

Brian