I'm trying to create a small piece of code in F#. The idea is that I would have an interface which defines a few methods, properties, and events. Using this interface I want to define an abstract class (having a generic type) which would implement some properties/methods but not all of the members defined in the interface. The responsibility to define all of the members would be on the derived classes.
So far I'm stuck with the interface and the abstract class. The problems I'm having:
- The abstract class definition does not recognize the interface definition
- I'm not sure how to define the abstract members for the interface in the abstract class
The interface compiles fine but the abstract class has several errors. The messages are included in code
All comments would be appreciated. Since this is my first trial on F# there are probably a lot of mistakes to point out :)
What I have tried:
Interface definition
namespace A
type IValueItem =
interface
[<CLIEvent>]
abstract member PropertyChanged :
Control.IEvent<System.ComponentModel.PropertyChangedEventHandler,
System.ComponentModel.PropertyChangedEventArgs>
abstract ConvertedX : double with get, set
abstract Y : double with get, set
abstract member CreateCopy : obj
abstract member NewTrendItem : obj
end
And the abstract class
namespace A
[<AbstractClass>]
type ValueItem<'TX>() =
[<DefaultValue>]
val mutable _y : double
let _propertyChanged = new Event<_>()
interface IValueItem with
[<CLIEvent>]
member this.PropertyChanged :
Control.IEvent<System.ComponentModel.PropertyChangedEventHandler,
System.ComponentModel.PropertyChangedEventArgs>
= _propertyChanged.Publish
member ConvertedX : double with get, set
member CreateCopy() : obj
member NewTrendItem() : obj
abstract X : 'TX with get, set
member this.Y
with get() = this._y
and set(value) =
if this._y <> value then
this._y <- value
this.NotifyPropertyChanged("Y")
member this.NotifyPropertyChanged(propertyName) =
this.PropertyChanged.Trigger(this, new System.ComponentModel.PropertyChangedEventArgs(propertyName))