Hi James,

I'm not suprised you haven't found the correct syntax, its a little verbose:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#light
type TestInterface = interface
    abstract DoSomething: unit -> unit
end

type ImplementInterface() = class
    interface TestInterface with
        override x.DoSomething() = printfn "base"
    end
    abstract DoSomething: unit -> unit
    override x.DoSomething() = 
        let inter = x :> TestInterface 
        inter.DoSomething()
end

type OverrideClass() = class 
    inherit ImplementInterface()
    override x.DoSomething() = printfn "something"
end

let base = ImplementInterface()
base.DoSomething()
let child = OverrideClass()
child.DoSomething()

I think all this is necessary because in F# interfaces are implmented implicitly, so you need to hold a refrence to the interface to call there methods not just a refernce, this seems to interfere with overriding a method in a child class. The solution is to add a new virtual method on the interface of the class itself, annoyingly this adds quite a bit of extra code. I'm sure this is one of the things Don will be looking at in productization.

Cheers,
Rob

By on 10/30/2007 10:00 PM ()
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