Re: not null



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

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



Relevant Pages

  • Re: List<> of struct with property. Cannot change value of property. why?
    ... method changes the struct that owns it. ... how would the compiler know the method changes the struct? ... Should the linker be required to carry this flag around too, so that when you import a reference to a struct type not compiled with the current project, you still have that information? ... There's a time and place for a value type, and in fact they even have their place in lists. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Maintain list of attached event handlers (.Net 1.1)
    ... Your requirement to unsubscribe when the event fires is completely independent of how you unsubscribe other events later. ... A basic rule of event management is that when you subscribe the first handler, the reference to the event has to be instantiated. ... While you didn't actually post any code that showed such an enumeration, I will take as granted that somewhere you actually do. ... It's simple, it works, and is MORE performant than trying to maintain a list or lists or other data structures as various events are raised and unsubscribed from. ...
    (microsoft.public.dotnet.framework)
  • Re: List<> of struct with property. Cannot change value of property. why?
    ... method changes the struct that owns it. ... so that when you import a reference to a struct type not ... tell it specifically that it doesn't change it, then the compiler ... have their place in lists. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Call by value, but (please check my hypothesis)
    ... objects are passed by reference in Lisp. ... > to lists ... SETF actually understands the syntax of the (GETF ...
    (comp.lang.lisp)
  • Re: [PATCH 2.6.23.14] SCSI : scsi_device_lookup/scsi_device_lookup_by_target return NULL for an exis
    ... because there is some outstanding command holding a reference to it. ... scanning will go ahead and try to add a new scsi_device to the devices lists. ... the consensus was to resurrect the sdev from the SDEV_DEL state back ... - that patches for the resurrection where implemented post this thread ...
    (Linux-Kernel)