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

I want to declare two related classes, so I declare them together connected by "and". Each of them has different attributes, but this code does not work (error "Unexpected keyword" and "in the definition" in the keyword "and". How to declare attributes of the second class?

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

This works for me. You did 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 and.

+8
source

Yes, I opened the System and yes, the solution should put it after and.

That!

+2
source

All Articles