Subscribe to The Madman Scribblings        RSS Feed
-----

Overridable Default Values For Null?

Icon 2 Comments
Overridable Default Values For Null? (Title is a link for more details)

Suppose we had the ability to express nonnull reference types in .net T!.
So there should be a way to express a default value, when null is assigned to a nonnull, since null is an illegal value for a nonnull.

The base class of all .net object is modified to have a new overriddable method default
To remain compatible these are override in Structure and Class return the current default<T> or null
[i]Special cased in the compiler/runtime to allow null in this override [i]

Now for your class to support nonnull-ability it has to override the current inherited implementation of Default.
nonnull class ObjT
{
  static _default : ObjT! = New ObjT()
  overrides default () : ObjT!
  {
    return _default_ /* One potential implementation */
  }
}



T! x = null ; /* x = T.Default */



What are you thoughts about having this ability in .net?

2 Comments On This Entry

Page 1 of 1

cfoley Icon

13 August 2014 - 02:15 AM
Have you considered writing a language? I know it's a big undertaking but a lot of your blogs are improvements, hacks and workarounds for existing languages.
0

AdamSpeight2008 Icon

31 August 2014 - 07:54 PM
cfoley I have but it not easy. I'm looking at the Roslyn stuff. Currently using it the create Diagnostics and code fixes.
0
Page 1 of 1