Here's an example using constructed class types that may give you some ideas:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#light

type IFoo =
    abstract Foo : unit -> unit


type A() =
    abstract Bar : unit -> unit
    default this.Bar() = printfn "from A"


    interface IFoo with
        member this.Foo() = this.Bar()
            

type B() =
    inherit A()
 
    override this.Bar() = base.Bar(); printfn "from B"
            

let a = A() :> IFoo
a.Foo()
// from A
let b = B() :> IFoo
b.Foo()
// from A
// from B
By on 9/2/2008 6:46 AM ()

I was struggling with this question too.

In the older release (1.9.4.19), I was able to do something like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#light

type IFoo =
    abstract Foo : unit -> unit

type A() =
    interface IFoo

    abstract Foo : unit -> unit
    default this.Foo() = printfn "from A"
           
type B() =
    inherit A()
 
    override this.Foo() = base.Foo(); printfn "from B"

That's was closest approximation to the default method implementation in the base class I could get.

But it's not possible to do anymore in the latest 1.9.6 release...
Why?

Is this idiom is not that useful in the F# programming as it was in the OO world?

thanks!
- Sergey

By on 9/3/2008 7:50 AM ()

Hi daniel,

I can see no way of doing this. The FSharp manual Section 14.8 Dispatch Slot Inference describes why this is the case.

regards,
Danny

By on 9/2/2008 5:09 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