NullReferenceException

1 view
Skip to first unread message

NN

unread,
Mar 21, 2010, 11:20:55 AM3/21/10
to Nemerle Forum
What about changing Nemerle type system to make NRE problems less
painful.

Today you can do the following:

def a = ["a", null, "b"];
And then if you want to print all values you have to do the following:

a.Filter(i => i != null).Iter(Console.WriteLine);

Pay attention to Filter method.
Why do you need it ? Because you can get null! Very very sad.

What can be a solution ?
Prevent using null values.

def a = ["a", null, "b"]; // Compilation Error

And if user wants null values , he must admit it.

def? a = ["a", null, "b"];
def a : list[CanBeNull[string]] = ["a", null, "b"];

The type CanBeNull[T] can be converted to T.

From the point of .Net.

T where T : class ==> Reference type with compile time restriction.
Can be used only in Nemerle code.
T where T : struct ==> T
CanBeNull[T] where T : class ==> Regular reference type. Can be used
for connecting code.
CanBeNull[T] where T : struct ==> Nullable<T>

Possible syntax for CanBeNull[T] - T?


class A
{
private x : string;
private y : string?;

F() : void
{
// if (x == null) // No need
Console.WriteLine(x);
if (y != null) // Can be null
Console.WriteLine(y);
}
}

What do you say about it ?

VladD2

unread,
Mar 21, 2010, 12:10:20 PM3/21/10
to nemer...@googlegroups.com
Hi

2010/3/21 NN <nn14...@gmail.com>

What about changing Nemerle type system to make NRE problems less
painful.


It's big task. I think, we implement it in Nemerle 2.0.

NN

unread,
Mar 22, 2010, 6:04:25 AM3/22/10
to Nemerle Forum
It is more theoretical question now.
Do you think it is possible and/or useful ?

It will be nice to make a list for possible Nemerle 2.0 features.

On Mar 21, 6:10 pm, VladD2 <v...@rsdn.ru> wrote:
> Hi
>
> 2010/3/21 NN <nn1436...@gmail.com>

VladD2

unread,
Mar 22, 2010, 8:23:40 AM3/22/10
to nemer...@googlegroups.com
2010/3/22 NN <nn14...@gmail.com>

It is more theoretical question now.
Do you think it is possible and/or useful ?

It is possible and useful.
Reply all
Reply to author
Forward
0 new messages