I'm trying to create an interface that requires additional methods on top of IEvent, like this:
我正在尝试创建一个在IEvent之上需要其他方法的接口,如下所示:
type Varying<'t> =
abstract member Get : unit -> 't
abstract member Set : 't -> unit
abstract member AddHandler : Handler<'t> -> unit
abstract member RemoveHandler : Handler<'t> -> unit
member v.Add(f) = v.AddHandler(new Handler<_>(fun _ x -> f x))
interface IEvent<'t> with
member c.AddHandler(h) = c.AddHandler(h)
member c.RemoveHandler(h) = c.RemoveHandler(h)
member c.Add(f) = c.Add(f)
I added the Get
& Set
methods. The problem is that the F# compiler wants me to implement the abstract members:
我添加了Get&Set方法。问题是F#编译器要我实现抽象成员:
No implementation was given for 'abstract member Varying.AddHandler : Handler<'t> -> unit'
没有给出'抽象成员Varying.AddHandler:Handler <'t> - > unit'的实现
But the point of this type is that the member is abstract. What am I doing wrong?
但这种类型的观点是该成员是抽象的。我究竟做错了什么?
1 个解决方案
#1
You can add [<AbstractClass>]
label to your definition:
您可以在定义中添加[
> [<AbstractClass>]
- type Varying<'t> =
- abstract member Get : unit -> 't
- abstract member Set : 't -> unit
- abstract member AddHandler : Handler<'t> -> unit
- abstract member RemoveHandler : Handler<'t> -> unit
- member v.Add(f) = v.AddHandler(new Handler<_>(fun _ x -> f x))
- interface IEvent<'t> with
- member c.AddHandler(h) = c.AddHandler(h)
- member c.RemoveHandler(h) = c.RemoveHandler(h)
- member c.Add(f) = c.Add(f)
- ;;
type Varying<'t> =
class
abstract member AddHandler : Handler<'t> -> unit
abstract member Get : unit -> 't
abstract member RemoveHandler : Handler<'t> -> unit
abstract member Set : 't -> unit
interface IEvent<'t>
member Add : f:('t -> unit) -> unit
end
#1
You can add [<AbstractClass>]
label to your definition:
您可以在定义中添加[
> [<AbstractClass>]
- type Varying<'t> =
- abstract member Get : unit -> 't
- abstract member Set : 't -> unit
- abstract member AddHandler : Handler<'t> -> unit
- abstract member RemoveHandler : Handler<'t> -> unit
- member v.Add(f) = v.AddHandler(new Handler<_>(fun _ x -> f x))
- interface IEvent<'t> with
- member c.AddHandler(h) = c.AddHandler(h)
- member c.RemoveHandler(h) = c.RemoveHandler(h)
- member c.Add(f) = c.Add(f)
- ;;
type Varying<'t> =
class
abstract member AddHandler : Handler<'t> -> unit
abstract member Get : unit -> 't
abstract member RemoveHandler : Handler<'t> -> unit
abstract member Set : 't -> unit
interface IEvent<'t>
member Add : f:('t -> unit) -> unit
end