www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [D typesystem] What is the type of null?

reply Justin Johansson <no spam.com> writes:
Given that if a function should return something,
and that function may return null in, at least
reference type return scenarios, one would expect that
"null" has a type.

What is the type of "null" in the D typesystem?

- JJ
Oct 12 2010
next sibling parent reply Stanislav Blinov <blinov loniir.ru> writes:
  12.10.2010 17:52, Justin Johansson пишет:
 Given that if a function should return something,
 and that function may return null in, at least
 reference type return scenarios, one would expect that
 "null" has a type.

 What is the type of "null" in the D typesystem?

 - JJ
writeln(typeid(typeof(null))) yields void* :)
Oct 12 2010
parent reply Justin Johansson <no spam.com> writes:
On 13/10/2010 1:34 AM, Stanislav Blinov wrote:
 12.10.2010 17:52, Justin Johansson пишет:
 Given that if a function should return something,
 and that function may return null in, at least
 reference type return scenarios, one would expect that
 "null" has a type.

 What is the type of "null" in the D typesystem?

 - JJ
writeln(typeid(typeof(null))) yields void* :)
Are you suggesting that the type of "null" is opaque or merely saying what the D compiler says without an opinion? - JJ
Oct 12 2010
parent reply Stanislav Blinov <blinov loniir.ru> writes:
  12.10.2010 18:43, Justin Johansson пишет:
 On 13/10/2010 1:34 AM, Stanislav Blinov wrote:
 12.10.2010 17:52, Justin Johansson пишет:
 Given that if a function should return something,
 and that function may return null in, at least
 reference type return scenarios, one would expect that
 "null" has a type.

 What is the type of "null" in the D typesystem?

 - JJ
writeln(typeid(typeof(null))) yields void* :)
Are you suggesting that the type of "null" is opaque or merely saying what the D compiler says without an opinion?
There was a smile there, no? Alright, alright, joking mood off. Personally, I'd suggest that null has no 'type' by itself, but adapts to whatever type is applicable in certain use case. It may be viewed as if D had several different 'nulls' for every existing and user-defined reference type.
Oct 12 2010
parent Justin Johansson <no spam.com> writes:
On 13/10/2010 2:17 AM, Stanislav Blinov wrote:
 There was a smile there, no? Alright, alright, joking mood off.
Of course there was a(n implied) smile there, sorry I forgot the opcodes :-) :-) :-) - JJ
Oct 12 2010
prev sibling next sibling parent reply Adam D. Ruppe <destructionator gmail.com> writes:
I agree with what the compiler says: void*.

null is literally a pointer into the void - there's nothing there
for it to point to.
Oct 12 2010
parent reply Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 10/12/10 9:51 CDT, Adam D. Ruppe wrote:
 I agree with what the compiler says: void*.

 null is literally a pointer into the void - there's nothing there
 for it to point to.
Problem: char[] a = null; The answer to the OP's question is simple: null's type is not expressible in D. Andrei
Oct 12 2010
parent reply Justin Johansson <no spam.com> writes:
On 13/10/2010 2:04 AM, Andrei Alexandrescu wrote:
 On 10/12/10 9:51 CDT, Adam D. Ruppe wrote:
 I agree with what the compiler says: void*.

 null is literally a pointer into the void - there's nothing there
 for it to point to.
Problem: char[] a = null; The answer to the OP's question is simple: null's type is not expressible in D.
 Andrei
That is a sad observation for a language that purports maturity beyond the epoch of C/C++/Java et. al. Justin
Oct 12 2010
parent reply "Simen kjaeraas" <simen.kjaras gmail.com> writes:
Justin Johansson <no spam.com> wrote:

 The answer to the OP's question is simple: null's type is not
 expressible in D.
That is a sad observation for a language that purports maturity beyond the epoch of C/C++/Java et. al.
I'm curious - why does null need such a specific type? -- Simen
Oct 12 2010
next sibling parent Justin Johansson <no spam.com> writes:
On 13/10/2010 2:41 AM, Simen kjaeraas wrote:
 Justin Johansson <no spam.com> wrote:

 The answer to the OP's question is simple: null's type is not
 expressible in D.
That is a sad observation for a language that purports maturity beyond the epoch of C/C++/Java et. al.
I'm curious - why does null need such a specific type?
I'm sure others can throw their thoughts in on this, however for me, on the other side of the world, it is way beyond the witching hour and I need to retire at least a few hours before the sun rises. Until later, enjoy your daylight time, Justin
Oct 12 2010
prev sibling parent reply retard <re tard.com.invalid> writes:
Tue, 12 Oct 2010 17:41:05 +0200, Simen kjaeraas wrote:

 Justin Johansson <no spam.com> wrote:
 
 The answer to the OP's question is simple: null's type is not
 expressible in D.
That is a sad observation for a language that purports maturity beyond the epoch of C/C++/Java et. al.
I'm curious - why does null need such a specific type?
It's much easier to write a specification, a compiler, and an automatic theorem prover for a language with a sane type system. The types and transitions are expressible with simple rules of logic. Now you need ad hoc special cases. Nothing else.
Oct 13 2010
parent reply Bruno Medeiros <brunodomedeiros+spam com.gmail> writes:
On 13/10/2010 17:27, retard wrote:
 Tue, 12 Oct 2010 17:41:05 +0200, Simen kjaeraas wrote:

 Justin Johansson<no spam.com>  wrote:

 The answer to the OP's question is simple: null's type is not
 expressible in D.
That is a sad observation for a language that purports maturity beyond the epoch of C/C++/Java et. al.
I'm curious - why does null need such a specific type?
It's much easier to write a specification, a compiler, and an automatic theorem prover for a language with a sane type system. The types and transitions are expressible with simple rules of logic. Now you need ad hoc special cases. Nothing else.
It may be true that such would make it easier to write an automatic theorem prover, maybe also a specification, but would it really make it easier to write a compiler for such a language? And more importantly, even if it was easier, would the language actually be a better and more useful language? Better as in a general-purpose programming language. I suspect not, and Justin's implication that D's inability to accurately express the type of null is somehow a severe shortcoming seems to me like wacky formal-methods fanboyism or some other similar crazyness... -- Bruno Medeiros - Software Engineer
Oct 29 2010
next sibling parent Stanislav Blinov <stanislav.blinov gmail.com> writes:
Bruno Medeiros wrote:
 On 13/10/2010 17:27, retard wrote:
 Tue, 12 Oct 2010 17:41:05 +0200, Simen kjaeraas wrote:

 Justin Johansson<no spam.com>  wrote:

 The answer to the OP's question is simple: null's type is not
 expressible in D.
That is a sad observation for a language that purports maturity beyond the epoch of C/C++/Java et. al.
I'm curious - why does null need such a specific type?
It's much easier to write a specification, a compiler, and an automatic theorem prover for a language with a sane type system. The types and transitions are expressible with simple rules of logic. Now you need ad hoc special cases. Nothing else.
It may be true that such would make it easier to write an automatic theorem prover, maybe also a specification, but would it really make it easier to write a compiler for such a language? And more importantly, even if it was easier, would the language actually be a better and more useful language? Better as in a general-purpose programming language. I suspect not, and Justin's implication that D's inability to accurately express the type of null is somehow a severe shortcoming seems to me like wacky formal-methods fanboyism or some other similar crazyness...
AFAIK, N/A is a fairly legit theorem outcome (laws involving infinity, or integral of sin(x)/x come to mind).
Oct 29 2010
prev sibling parent reply el muchacho <nicolas.janin gmail.com> writes:
Le 29/10/2010 21:02, Bruno Medeiros a écrit :
 On 13/10/2010 17:27, retard wrote:
 Tue, 12 Oct 2010 17:41:05 +0200, Simen kjaeraas wrote:

 Justin Johansson<no spam.com>  wrote:

 The answer to the OP's question is simple: null's type is not
 expressible in D.
That is a sad observation for a language that purports maturity beyond the epoch of C/C++/Java et. al.
I'm curious - why does null need such a specific type?
It's much easier to write a specification, a compiler, and an automatic theorem prover for a language with a sane type system. The types and transitions are expressible with simple rules of logic. Now you need ad hoc special cases. Nothing else.
It may be true that such would make it easier to write an automatic theorem prover, maybe also a specification, but would it really make it easier to write a compiler for such a language? And more importantly, even if it was easier, would the language actually be a better and more useful language? Better as in a general-purpose programming language. I suspect not, and Justin's implication that D's inability to accurately express the type of null is somehow a severe shortcoming seems to me like wacky formal-methods fanboyism or some other similar crazyness...
Hello, I don't know if it has already been cited here, but this is a good read : Much Ado About Nothing: Putting Java’s Null in its Place http://www.ccs.neu.edu/scheme/pubs/dissertation-cobbe.pdf
Oct 31 2010
parent lurker <lurk lurking.org> writes:
el muchacho Wrote:
 
 I don't know if it has already been cited here, but this is a good read :
 Much Ado About Nothing: Putting Java’s Null in its Place
 http://www.ccs.neu.edu/scheme/pubs/dissertation-cobbe.pdf
I only saw words Haskell and Java there. Was enough to make me vomit and made my brain refuse to read more. We don't need Java bloat or Haskell academics in practical systems programming. There's no way to avoid null.
Oct 31 2010
prev sibling next sibling parent dsimcha <dsimcha yahoo.com> writes:
== Quote from Justin Johansson (no spam.com)'s article
 Given that if a function should return something,
 and that function may return null in, at least
 reference type return scenarios, one would expect that
 "null" has a type.
 What is the type of "null" in the D typesystem?
 - JJ
I see it as a polysemous value, kind of like 1. typeof(1) is int. auto foo = 1; makes foo an int. However, the literal 1 can be assigned to any integral type, even ones that an int can't be. Similarly, null can be assigned to class references and pointers to any type, even though a void* can't be.
Oct 12 2010
prev sibling parent "Simen kjaeraas" <simen.kjaras gmail.com> writes:
On Tue, 12 Oct 2010 15:52:36 +0200, Justin Johansson <no spam.com> wrote:

 Given that if a function should return something,
 and that function may return null in, at least
 reference type return scenarios, one would expect that
 "null" has a type.

 What is the type of "null" in the D typesystem?
The type of null is Null. This type is castable to any pointer or reference type, as well as arrays. Now, this is of course not true, but it could have been. -- Simen
Oct 12 2010