🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #365

Can laziness sometimes be too lazy?

#365
From: Mike McGaughey
Date: Fri, 20 Jul 1990 01:16
31 lines
1414 bytes
Are there situations where lazy evaluation is *too* lazy?

The following example (due to Lloyd Alison) shows what I mean:

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?

Mike.
--
Mike McGaughey			ACSNET:	mmcg@bruce.cs.monash.oz
Technical Details
Message-ID: <2706@bruce.cs.monash.OZ.AU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!samsung!munnari.oz.au!bruce!mmcg

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!clyde.concordia.ca!uunet!tut.cis.ohio-state.edu!cs.utexas.edu!samsung!munnari.oz.au!bruce!mmcg
From: mmcg@bruce.cs.monash.OZ.AU (Mike McGaughey)
Newsgroups: comp.lang.functional
Subject: Can laziness sometimes be too lazy?
Message-ID: <2706@bruce.cs.monash.OZ.AU>
Date: 20 Jul 90 01:16:04 GMT
Organization: Monash Uni. Computer Science, Australia
Lines: 31