|
 |
>>> What would the harm be if eg. list nodes were structs instead?
>
>> Since "null" is a union in Haskell to (i.e., it either has data in it or it
>> has no data in it), this wouldn't really save you anything.
>
> It saves checking the node type for each single operation you do to any
> node in the list. It the node is a struct, its contents are fixed and thus
> you don't have to check anything.
On the other hand, in a language where unions appear all over the place,
the implementors go to great lengths to make it really efficient.
Besides, normally just about any code that does stuff to a linked list
ends up doing something like
while (list != null)
do stuff;
list = next node;
So there's a check in there anyway. All we're doing by using a union is
making it a different check.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |