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.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM 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!postnews.google.com!l39g2000yqn.googlegroups.com!not-for-mail From: Harald Korneliussen Newsgroups: comp.lang.ada Subject: Re: not null Date: Fri, 6 Mar 2009 05:05:40 -0800 (PST) Organization: http://groups.google.com Message-ID: 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> <87mybyg6tv.fsf@nbi.dk> NNTP-Posting-Host: 87.238.45.15 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1236344740 14655 127.0.0.1 (6 Mar 2009 13:05:40 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 6 Mar 2009 13:05:40 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: l39g2000yqn.googlegroups.com; posting-host=87.238.45.15; posting-account=S7g0VAoAAAAdFBi5JmasOpOeJipGobpl User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.7) Gecko/2009030422 Ubuntu/8.10 (intrepid) Firefox/3.0.7,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:3989 Date: 2009-03-06T05:05:40-08:00 List-Id: On Mar 6, 1:43=A0pm, Jacob Sparre Andersen wrote: > Harald Korneliussen wrote: > > You can use algebraic data types to do that in a type safe manner. > > 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. > > Can this be implemented as a static check? =A0(Or is there a good reason > that it is only a warning?) > > It would be nice(TM) if Ada compilers could do something like that for > with null access types. > It can be enforced, of course. It could be implemented in Ada, but to do it without serious program analysis, I think there would need to be a special function that separates the cases (Null and not null) and sends the program down one path or the other - naturally, with only the not-null path having access to a variable of the base type. The compiler could then insure that (almost) the only operation that could be performed on the possibly-null type was this function. In Haskell and Ocaml this is done with pattern matching on types.