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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,839916f6ca3b6404 X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news1.google.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!cyclone1.gnilink.net!gnilink.net!nx01.iad.newshosting.com!newshosting.com!newsfeed2.ip.tiscali.net!tiscali!newsfeed1.ip.tiscali.net!newsfeed00.sul.t-online.de!t-online.de!inka.de!rz.uni-karlsruhe.de!news.belwue.de!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Fri, 06 Mar 2009 21:05:25 +0100 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.19 (Macintosh/20081209) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: not null 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> <1so528ceh38jq$.uws9l96ursub.dlg@40tude.net> <11kj0o80w9j7k.15bjz2vugzuvv$.dlg@40tude.net> In-Reply-To: <11kj0o80w9j7k.15bjz2vugzuvv$.dlg@40tude.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <49b18206$0$31339$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 06 Mar 2009 21:05:26 CET NNTP-Posting-Host: f48f9b50.newsspool4.arcor-online.net X-Trace: DXC=^P4:]`E9KL[Fm0Y?OE@2^X4IUK Dmitry A. Kazakov schrieb: > On Fri, 6 Mar 2009 08:59:41 -0800 (PST), Harald Korneliussen wrote: > >>> 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: >> I don't understand your code example. But kind of like some Java >> functions won't compile unless they're surrounded by an appropriate >> try/catch block, you can make in Haskell a linked list get_next >> function that causes the compiler to protest - at compile time, >> naturally - if used in a context where the possibility of returning >> Nothing (null) isn't considered. HUGS at least does not seem to complain about a function definition that does not have a definition for a Nothing argument. (Example shows something like Ada's accessing an array named cs at index k with bounds checks handled proactively. Haskell's index operator !! does raise index errors.) module M where element :: [Char] -> Int -> Maybe Char element cs k = if k >= 0 && k < (length cs) then Just (cs !! k) else Nothing test :: Maybe a -> a test (Just x) = x -- test Nothing = '!' -- deliberately commented main = putChar( test (element("ABC")(3))) M> main Program error: pattern match failure: test Nothing > But this has nothing to do with null as a value. It does to exception > handling. The problem was moved to the client, which is the point. > > (It is a pity that Ada does not have contracted exceptions.) But isn't it really the client that should deal with contracts that it violates? If there are more capable Haskell translators, they should be able to reject the definition of function ``test'' just like Ada rejects a case statement that does not cover all values. GHC does at least warn. (I'm not that familiar with Haskell.)