comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: not null
Date: Fri, 6 Mar 2009 16:21:53 +0100
Date: 2009-03-06T16:21:53+01:00	[thread overview]
Message-ID: <1so528ceh38jq$.uws9l96ursub.dlg@40tude.net> (raw)
In-Reply-To: 3234a1e2-5f7a-4a26-8b7b-65e3ac67d65f@s20g2000yqh.googlegroups.com

On Fri, 6 Mar 2009 04:01:45 -0800 (PST), Harald Korneliussen wrote:

> On Mar 4, 5:09�pm, Adam Beneschan <a...@irvine.com> 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



  parent reply	other threads:[~2009-03-06 15:21 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-03-04 14:44 not null Georg Bauhaus
2009-03-04 14:56 ` Hyman Rosen
2009-03-04 15:22   ` Georg Bauhaus
2009-03-04 16:16     ` Adam Beneschan
2009-03-05 14:24       ` Georg Bauhaus
2009-03-05 16:07         ` Adam Beneschan
2009-03-06  1:07       ` Hibou57 (Yannick Duchêne)
2009-03-04 16:09   ` Adam Beneschan
2009-03-04 20:38     ` Dmitry A. Kazakov
2009-03-05  1:54       ` Adam Beneschan
2009-03-05  8:42         ` Dmitry A. Kazakov
2009-03-05  1:32     ` Brian Drummond
2009-03-05  1:47       ` Adam Beneschan
2009-03-05 11:32         ` Brian Drummond
2009-03-05 15:06           ` Dmitry A. Kazakov
2009-03-05 13:57         ` Georg Bauhaus
2009-03-05 19:53       ` Jack Mitchell
2009-03-05  8:49     ` Jacob Sparre Andersen
2009-03-05 16:10       ` Adam Beneschan
2009-03-05 17:20         ` Jacob Sparre Andersen
2009-03-06  1:04     ` Hibou57 (Yannick Duchêne)
2009-03-06 12:01     ` Harald Korneliussen
2009-03-06 12:43       ` Jacob Sparre Andersen
2009-03-06 13:05         ` Harald Korneliussen
2009-03-06 15:21       ` Dmitry A. Kazakov [this message]
2009-03-06 16:59         ` Harald Korneliussen
2009-03-06 17:48           ` Dmitry A. Kazakov
2009-03-06 20:05             ` Georg Bauhaus
2009-03-06 21:31               ` Dmitry A. Kazakov
2009-03-04 16:19   ` Robert A Duff
2009-03-04 20:39 ` Colin Paul Gloster
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox