我正在使用 orleankka 在 orleans 框架之上编写一个小型机器学习引擎。我需要一个父子类关系,其中父级支持获取、设置、默认构造函数和序列化。我的尝试在 F# 中失败了。
更新:使用接口现在我只需要弄清楚图像通道对象的序列化。
type imagechannel = int * int * char array[][]
type Iobject =
abstract Value : obj with get, set
abstract FromSerial : SerializationInfo -> StreamingContext -> unit
abstract ToSerial : SerializationInfo -> StreamingContext -> unit
type ImageChannel() =
let mutable value : option<imagechannel> = None
interface Iobject with
member this.Value with get() = value :> obj and set v = value <- v :?> option<imagechannel>
member this.FromSerial info context =
member this.ToSerial info context =
上下文代码:
type ProcessorMessage =
| Eval of (Iobject -> Parms -> Iobject) * Parms
| New of Iobject
| Value
| Load of cache
| Save of cache
| Trans of string * (Iobject -> Parms -> Iobject) * Parms
type Processor() =
inherit Actor<ProcessorMessage>()
let mutable value :option<Iobject> = None
override this.Receive message reply = task {
match message with
| Eval(fn,p) -> value <- (fn value p)
| Load(cache) -> //deserialize value
| Save(cache) -> //serialize value
| New(v) -> value <- v
| Value -> reply value
| Trans(addr,fn,p) -> let proc = this.System.ActorOf(addr)
proc <! New (fn value p) |> ignore
}
我应该直接实现序列化接口吗?如何用不同类型覆盖抽象值成员?还有其他建议吗?