Skip to content

Instantly share code, notes, and snippets.

@isaksky

isaksky/dispatch.fs

Created Apr 20, 2018
Embed
What would you like to do?
type Base() =
member x.Method() = "base method";
type Derived() =
inherit Base()
member x.Method() = "derived method"
type Base with
member x.Extension() = "base extension"
type Derived with
member x.Extension() = "derived extension"
let a = Base()
let b = Derived()
printfn "%s" (a.Method())
printfn "%s" (b.Method())
printfn "%s" (a.Extension())
printfn "%s" (b.Extension())
(*
base method
derived method
base extension
derived extension
*)
@isaksky

This comment has been minimized.

Copy link
Owner Author

@isaksky isaksky commented Apr 20, 2018

Woops, saw that I misread - the let b should be upcast to Base.

@isaksky

This comment has been minimized.

Copy link
Owner Author

@isaksky isaksky commented Apr 20, 2018

Correction:

let a = Base()
let b = Derived() :> Base
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment