Why do you need an extra keyword -- wouldn't a missing property body be clue enough?

By on 8/31/2009 10:21 AM ()

To provide a declaration

By on 9/9/2009 10:32 PM ()

perhaps... but I fear the compiler might get confused with the abstract member declaration.

By on 8/31/2009 10:47 AM ()

Hi,
I think the F# team thought about adding something like this, but it's probably more difficult than it seems. One possible problem with this feature is initialization of the property. F# tries to avoid using "uninitalized value" where possible, so when adding some syntax like this, you'd also need some way to initialize the property during construction of the class. This complicates the (otherwise simple) feature quite a bit.

Anyway, most of the classes written in F# will probably be designed as immutable, which makes the problem a bit easier, because you don't need a setter. In that case, you can write the code quite simply like this:

1
2
3
4
 
type SomeClass(n) =
  let myPropValue = n * 2
  member x.MyProp = myPropValue

Anyway, I agree that a feature like the one you suggest would be a nice addition in some future version.

By on 8/31/2009 2:52 PM ()

Actually, I was hoping for this feature especially for scenarios where one does NOT want to use immutable values. For example, with NHibernate (which has very particular modeling requirements due to its implementation). As to the initialization, is there some problem with auto-generating the DefaultValueAttribute as part of the synthesized backing field? After all, it crops up all over ASP.NET.

By on 8/31/2009 6:44 PM ()

As to the initialization, is there some problem with auto-generating the DefaultValueAttribute as part of the synthesized backing field? After all, it crops up all over ASP.NET.

DefaultValueAttribute has absolutely nothing to do with field/property initialization (i.e. putting it on a property won't make this property magically initialized with whatever value you specify via the attribute).

By on 9/3/2009 2:03 PM ()

Okay, then, elucidate me: for what is the DefaultValueAttribute used?

By on 9/4/2009 7:42 AM ()

Ignore my last post. I just looked up the documentation for DefaultValueAttribute. However, I still don't see why field initialization is such a big deal if you already know you're going to be dealing with some wonky mutable code.

By on 9/4/2009 7:47 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