From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,839916f6ca3b6404 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news3.google.com!feeder.news-service.com!newsfeed.straub-nv.de!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: not null Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 8bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <49ae93bc$0$31872$9b4e6d93@newsspool3.arcor-online.net> <761a4fb8-de91-43b3-b420-55dbc06a61e7@k9g2000prh.googlegroups.com> <3234a1e2-5f7a-4a26-8b7b-65e3ac67d65f@s20g2000yqh.googlegroups.com> Date: Fri, 6 Mar 2009 16:21:53 +0100 Message-ID: <1so528ceh38jq$.uws9l96ursub.dlg@40tude.net> NNTP-Posting-Date: 06 Mar 2009 16:21:53 CET NNTP-Posting-Host: 94b8ec0f.newsspool3.arcor-online.net X-Trace: DXC=66L72Pko[`AAa;:RKVJ>LEMcF=Q^Z^V3H4Fo<]lROoRA^YC2XCjHcbI1obUf_i?@_GDNcfSJ;bb[EFCTGGVUmh?DLK[5LiR>kgB\9U^eR4_d4L X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:3992 Date: 2009-03-06T16:21:53+01:00 List-Id: On Fri, 6 Mar 2009 04:01:45 -0800 (PST), Harald Korneliussen wrote: > On Mar 4, 5:09�pm, Adam Beneschan 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