I am unclear exactly what is desired, but below code is suggestive of one strategy (abstract base class that implements interface and has abstract/virtual members for implementation of interface that can overriden or filled out by subclasses).

1
2
3
4
5
6
7
8
9
10
11
12
13
14
 
type IStatistic =
    abstract Accumulate : int -> unit
    abstract Compute : unit -> float
    
[<AbstractClass>]
type StatBase =
    member this.Foo() = ()
    abstract AccumulateImpl : int -> unit
    abstract ComputeImpl : unit -> float
    default this.ComputeImpl() = raise <| new System.NotImplementedException()
    interface IStatistic with
        member this.Accumulate x = this.AccumulateImpl x
        member this.Compute() = this.ComputeImpl()
By on 7/30/2009 9:47 AM ()

none,
With the code i posted above, I get 2 compiler errors for the missing implementation of StatBase.Accumulate and StatBase.Compute.

Brian,
Iyour solution is fine, I was wondering if it's possible to have a shorter syntax like in my example.

Cheers :)

By on 9/2/2009 4:57 AM ()

Nevermind, it was enough to add the AbstractClass attribute to my original code. Doh!
The following works fine :-)

1
2
3
4
5
6
7
8
9
10
    type IStatistic =
        abstract Accumulate : int -> unit
        abstract Compute : unit -> float
    
    [<AbstractClass>]
    type StatBase =
        interface IStatistic
            abstract Accumulate : int -> unit
            abstract Compute : unit -> float
        member this.Clone () =  (this :> obj).MemberwiseClone()
By on 9/2/2009 6:07 AM ()

I get an error on the MemberwiseClone() function. Other than that, everything seems to compile fine. (if i return this from Clone()) What are you trying to do?

By on 7/30/2009 9:46 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper