comp.lang.ada
 help / color / mirror / Atom feed
From: Georg Bauhaus <rm.dash-bauhaus@futureapps.de>
Subject: Re: not null
Date: Fri, 06 Mar 2009 21:05:25 +0100
Date: 2009-03-06T21:05:26+01:00	[thread overview]
Message-ID: <49b18206$0$31339$9b4e6d93@newsspool4.arcor-online.net> (raw)
In-Reply-To: <11kj0o80w9j7k.15bjz2vugzuvv$.dlg@40tude.net>

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.)



  reply	other threads:[~2009-03-06 20:05 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
2009-03-06 16:59         ` Harald Korneliussen
2009-03-06 17:48           ` Dmitry A. Kazakov
2009-03-06 20:05             ` Georg Bauhaus [this message]
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