Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
14
Task/Polymorphic-copy/F-Sharp/polymorphic-copy.fs
Normal file
14
Task/Polymorphic-copy/F-Sharp/polymorphic-copy.fs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
type T() =
|
||||
// expose protected MemberwiseClone method (and downcast the result)
|
||||
member x.Clone() = x.MemberwiseClone() :?> T
|
||||
// virtual method Print with default implementation
|
||||
abstract Print : unit -> unit
|
||||
default x.Print() = printfn "I'm a T!"
|
||||
|
||||
type S() =
|
||||
inherit T()
|
||||
override x.Print() = printfn "I'm an S!"
|
||||
|
||||
let s = new S()
|
||||
let s2 = s.Clone() // the static type of s2 is T, but it "points" to an S
|
||||
s2.Print() // prints "I'm an S!"
|
||||
Loading…
Add table
Add a link
Reference in a new issue