Article View: comp.lang.functional
Article #387Re: Can laziness sometimes be too lazy?
From: Joe Keane
Date: Wed, 25 Jul 1990 19:19
Date: Wed, 25 Jul 1990 19:19
34 lines
1700 bytes
1700 bytes
How about the following C function:
struct list
{
int length;
ITEM* items;
};
struct list* first(length, old)
int length;
struct list* old;
{
struct list* new = (struct list*)malloc(sizeof(struct list));
int i;
new->length = length;
new->items = (ITEM*)malloc(length * sizeof(ITEM));
for (i = 0; i < length; i++)
new->items[i] = old->items[i];
return new;
}
This is a fairly close translation of the functional version of the first
function. You could easily make it recursive but i think it's a little
clearer in the iterative form. Note that it makes exactly the same mistake as
the functional version. It doesn't check the length of the old list, so the
new list may include some invalid elements.
I think the question is whether a list should be allowed to have elements
which raise exceptions. Certainly if the list is declared to have elements of
a specific type, then it can't. If the elements can be of any type, then
maybe. In a language with good exception handling, you would be able to
declare a list of elements which don't raise exceptions, or declare a list of
elements which may raise exceptions. You can get specific and say which kinds
of exceptions are allowed. It's like Burger King, have it your way.
Technical Details
Message-ID:
<3197@osc.COM>Path:
arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!sdd.hp.com!ucsd!pacbell.com!pacbell!osc!jgkReferences:
<3188@osc.COM> <2734@bruce.cs.monash.OZ.AU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!decwrl!sdd.hp.com!ucsd!pacbell.com!pacbell!osc!jgk From: jgk@osc.COM (Joe Keane) Newsgroups: comp.lang.functional Subject: Re: Can laziness sometimes be too lazy? Message-ID: <3197@osc.COM> Date: 25 Jul 90 19:19:37 GMT References: <3188@osc.COM> <2734@bruce.cs.monash.OZ.AU> Reply-To: jgk@osc.COM (Joe Keane) Organization: Object Sciences Corp., Menlo Park, CA Lines: 34