type Foo(x : int) =
member v.MyX() = x;;
let foo = {new Foo(3) with member v.MyX() = 4};;

Add an abstract definition for MyX, then make the original definition the default:

#light
type Foo(x : int) =
abstract member MyX : int
override it.MyX :int = x

{new Foo(3) with member it.MyX = 4}.MyX
--returns "4" as you desired.

NOTE: I removed the "()", because the abstract member definition needed a type declaration, and that was the only way I knew how to declare a type for a member that takes no arguments.

~TMSteve

By on 3/15/2008 9:44 PM ()

Here is a unit function decleration

abstract member MyX : unit -> int

By on 3/15/2008 9:54 PM ()

Hi namin,
Yes they are identical and yes new is optional. but I think it is a good practice to use it.

For the second part, myX is not an abstract function to override. Actually I would also suspect to hide the member and print as 4, but at the end the expression returns a type of Foo, there is no inheritence or override going in the expression. So the method that you have hidden is not called

Regards

By on 3/12/2008 5:09 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