Path: 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: <14531@dime.cs.umass.edu> Organization: UEA, Norwich, UK Lines: 51 In article lambert@spectrum.eecs.unsw.oz (Tim Lambert) writes: >In article 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