Re: not null
- From: "Dmitry A. Kazakov" <mailbox@xxxxxxxxxxxxxxxxx>
- Date: Fri, 6 Mar 2009 16:21:53 +0100
On Fri, 6 Mar 2009 04:01:45 -0800 (PST), Harald Korneliussen wrote:
On Mar 4, 5:09 pm, Adam Beneschan <a...@xxxxxxxxxx> wrote:
I'm having difficulty understanding the point. You have to have the
idea of the lack of a reference. How else would you implement a
linked list abstraction?
You can use algebraic data types to do that in a type safe manner.
No, you cannot, if safe = static. The nodes of the list have contracts to
support certain operations. The only problem with null is that the virtual
object corresponding to null does not fulfill the contract:
Do_It (Next (Node)) raises Constraint_Error, instead of doing things.
Whether you replace null with a reference to some fake object would change
nothing. The fact is, beyond the list end there is no objects fulfilling
the contract. Period.
Haskell, Ocaml and many smaller functional languages do: If a function
returns a "Maybe Integer" type, the compiler will warn you if you
pretend it's an Integer without dealing with the "Nothing" case.
Same in Ada:
type Base_Node is ...;
function Next (X : Base_Node) return Base_Node'Class;
type Node is new No_Node with ...
procedure Do_It (X : Node);
The compiler gives you an error (much better than warning) when you call
Do_It on something that is not in Node'Class. You have to cast it to Node
first and have a chance of Constraint_Error. What does change? Nothing.
So the point Adam IMO makes. If you do it dynamically checked null is as
good as anything else. Statically it is does not go, unless lists are
infinite or cyclic.
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
.
- Follow-Ups:
- Re: not null
- From: Harald Korneliussen
- Re: not null
- References:
- not null
- From: Georg Bauhaus
- Re: not null
- From: Hyman Rosen
- Re: not null
- From: Adam Beneschan
- Re: not null
- From: Harald Korneliussen
- not null
- Prev by Date: Re: not null
- Next by Date: Re: anonymous access type
- Previous by thread: Re: not null
- Next by thread: Re: not null
- Index(es):
Relevant Pages
|