Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to define different attributes for recursive classes in F#

Tags:

attributes

f#

I want to declare two classes that are associated, therefore I am declaring them together linked by an 'and'. Each has different attributes but this code is not working ("Unexpected keyword 'and' in definition" error at keyword 'and'. How should I declare the attributes of the second class?

[<AbstractClass>]
type foo() =
  abstract member fun1 : foo -> foo2
[<Serializable>]
and foo2() = class
  member x.bar y = y
end
like image 677
Bernadette Avatar asked Dec 17 '09 12:12

Bernadette


2 Answers

It works for me. Did you do open System?

open System

[<AbstractClass>]
type foo() =
  abstract member fun1 : foo -> foo2
and [<Serializable>] foo2() = class
  member x.bar y = y
end

Edit: Ah, it seems that the second attribute should be AFTER the and.

like image 52
Stringer Avatar answered Nov 18 '22 17:11

Stringer


Yes, I opened System and yes the solution is to place it after the and.

Ta!

like image 22
Bernadette Avatar answered Nov 18 '22 16:11

Bernadette