🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #366

Re: Can laziness sometimes be too lazy?

#366
From: Tom Blenko
Date: Fri, 20 Jul 1990 05:53
44 lines
1932 bytes
In article <2706@bruce.cs.monash.OZ.AU> mmcg@bruce.cs.monash.OZ.AU (Mike McGaughey) writes:
|
|let rec first n l =
|		if n = 0 then []
|		else (hd l).(first (n-1) (tl l))
|and rec length l =
|		if l = [] then 0
|		else 1 + length (tl l)
|in
|    length (first 2 [])
|
|In a strict language, the result is an error, due to the (tl []) in "first".
|
|In a lazy language (LML here), you get the result 2.
|
|If we replace those IFs with pattern matching, which is slightly
|stricter than it needs to be, we get a pattern match failure.
|
|The problem, in this case, is that "length" is passed a list of
|closures (of length 2) which are never evaluated, but which correspond
|to nonexistent list elements.
|
|Is this problem well known?  Has anyone any insight into what the
|language "should" do, and why?  Is it just a case of the increased
|freedom of laziness introducing a more subtle class of errors?

I don't think there's a good answer to your question (as it relates to
this example, anyway) unless it is clear what 'first' is intended to
mean.  The given definition for 'first' appears to be incorrect.

What is supposed to be the result of

	(first 2 [])

for example? A "correct" version of 'first' might be

	let rec cfirst n l =
			if n = 0 then []
			else if l = [] then []
			else (hd l).(cfirst (n-1) (tl l))

in which case the indicated behavior does not occur.

	Tom
Technical Details
Message-ID: <25607@cs.yale.edu>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!yale!quasi-eli!cs.yale.edu!blenko-tom
References: <2706@bruce.cs.monash.OZ.AU>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!rutgers!cs.utexas.edu!yale!quasi-eli!cs.yale.edu!blenko-tom
From: blenko-tom@CS.YALE.EDU (Tom Blenko)
Newsgroups: comp.lang.functional
Subject: Re: Can laziness sometimes be too lazy?
Message-ID: <25607@cs.yale.edu>
Date: 20 Jul 90 05:53:33 GMT
References: <2706@bruce.cs.monash.OZ.AU>
Sender: news@cs.yale.edu
Reply-To: blenko-tom@CS.YALE.EDU (Tom Blenko)
Organization: Yale University Computer Science Dept, New Haven CT  06520-2158
Lines: 44