🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.functional
Article #243

Re: Laziness and Back-to-front Lists

#243
From: Richard Kennaway
Date: Thu, 31 May 1990 11:42
51 lines
2570 bytes
In article <LAMBERT.90May30224949@nankeen.spectrum.cs.unsw.oz.au> lambert@spectrum.eecs.unsw.oz (Tim Lambert) writes:

>In article <BJORNL.90Jul28100843@tarpon.tds.kth.se> bjornl@tds.kth.se (Bj|rn Lisper) writes:
>% For instance, if(b,x,y) defined by
>% 
>% b => if(b,x,y) = x
>% not b => if(b,x,y) = y
>% 
>% is a (non-strict) function in three arguments. Left-to-right lazy evaulation
						  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
This is rather a contradiction in terms.  The left-to-right (and dont
forget top-to-bottom as well) strategy is lazier than strict evaluation,
but not as lazy as possible.  It is possible to be lazier, but it takes
more work :-).

>% will give the ordinary "conditional" semantics. As I pointed out, there are
>% cases where other evaluation orders terminate whereas this doesn't.

>If you want a different evaluation order you can define it (in
>Miranda) like this:

>> if b x x = x
>> if True x y = x
>> if False x y = y

>Now if is strict in its second and third arguments but not its first
>one.

...but you then get an error if the second and third arguments
are functions (Miranda doesnt let you compare functions for equality -
which is reasonable).  The ordinary definition of if (i.e. omit the first
rule above) works fine for functions.

>% Of course. A more interesting example is multiplication, that strictly
>% speaking (sic!) is non-strict, since whenever one argument returns zero the
>% other argument is not needed. if f(x) is non-terminating, then 0*f(x) still
>% terminates (and returns zero) if '*' is treated as a non-strict function
>% with left-to-right evaluation order. Is '*' usually implemented as a strict
>% or as a non-strict operator in lazy functional languages?

>Strict, since if you don't like this you can easily roll your own:

>> 0 $times y = 0
>> x $times y = x*y

This is only lazy in its first argument, not its second.  In Miranda,
you cant define a multiplication which is lazy in both arguments.

--
Richard Kennaway          SYS, University of East Anglia, Norwich, U.K.
Internet:  jrk@sys.uea.ac.uk		uucp:  ...mcvax!ukc!uea-sys!jrk
Technical Details
Message-ID: <1541@sys.uea.ac.uk>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!sys.uea!jrk
References: <BJORNL.90May29165842@pike.tds.kth.se> <14531@dime.cs.umass.edu> <LAMBERT.90May30224949@nankeen.spectrum.cs.unsw.oz.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!mcsun!ukc!sys.uea!jrk
From: jrk@sys.uea.ac.uk (Richard Kennaway)
Newsgroups: comp.lang.functional
Subject: Re: Laziness and Back-to-front Lists
Message-ID: <1541@sys.uea.ac.uk>
Date: 31 May 90 11:42:03 GMT
References: <BJORNL.90May29165842@pike.tds.kth.se> <14531@dime.cs.umass.edu> <LAMBERT.90May30224949@nankeen.spectrum.cs.unsw.oz.au>
Organization: UEA, Norwich, UK
Lines: 51