Hi Ivan,

This is a bug: the record building construct "{ a with i = 5 }" is for use with record types, not class types. No check to this effect is being made.

Thanks

Don

By on 8/26/2006 3:10 AM ()

Ah. So if that is illegal in F#, is there a way to clone an object without having to explicitly copy each member?

In particular if I have a class A and class B that inherits from class A and adds a field c, is there a way to write something that would have the effect of let (b:B) = { (a:A) with c = 3 }?

What I'm after ideally is something like row polymorphism in OCaml - how would I go about simulating that in F#?

Ivan

By on 8/26/2006 3:27 AM ()

There are two halves to this. In principle it is reasonable to support variations on the "{obj with rebinds}" cloning construct for F# and .NET objects, at least where the representations (e.g. fields) of those types have not been hidden by module signatures. For example, rebinding a single method or property would delegate the remainder of the method/property implementations to "obj". It is also feasible to support this as one of the techniques for defining an object constructor.

However, there are limitations here that are fairly inherent in the .NET object model. OCaml row polymorphism itself is not directly representable. Furthermore it is often the case that some or all of the representation of an object-model type is hidden (making cloning difficult), and there is no real "standard" for partial-cloning constructors on .NET.

Using records for concrete representations with interface implementations to factor commonality may often be a suitable substitute.

Cheers!

Don

By on 8/26/2006 5:20 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