From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA21888; Mon, 6 Sep 2004 19:00:52 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA23239 for ; Mon, 6 Sep 2004 19:00:51 +0200 (MET DST) Received: from smtp1.adl2.internode.on.net (smtp1.adl2.internode.on.net [203.16.214.181]) by concorde.inria.fr (8.13.0/8.13.0) with ESMTP id i86H0m3p020921 for ; Mon, 6 Sep 2004 19:00:50 +0200 Received: from [192.168.1.200] (ppp210-32.lns2.syd3.internode.on.net [203.122.210.32]) by smtp1.adl2.internode.on.net (8.12.9/8.12.9) with ESMTP id i86H0g4Y067086; Tue, 7 Sep 2004 02:30:43 +0930 (CST) Subject: RE: [Caml-list] laziness From: skaller Reply-To: skaller@users.sourceforge.net To: Jason Smith Cc: caml-list , Richard Jones In-Reply-To: <413AB81F@webmail> References: <413AB81F@webmail> Content-Type: text/plain Message-Id: <1094490041.3352.1193.camel@pelican.wigram> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.2 (1.2.2-4) Date: 07 Sep 2004 03:00:42 +1000 Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 413C97C0.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; caml-list:01 sourceforge:01 2004:99 eagerly:01 lazily:01 arggg:01 horror:99 strictness:01 debugging:01 optimise:01 eagerly:01 crashes:01 inlining:01 optimising:01 sloppy:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Mon, 2004-09-06 at 22:17, Jason Smith wrote: > I'm not sure i follow you here. How can you *not* use something? Like this: let f x y = x in f 1 (2/0) Well y isn't used in the function. If you rewrite it like this (eagerly): x = 1 y = (2/0) x then you divide by zero, but if you rewrite it like this (lazily): 1 then (2/0) isn't used. > Um, ok so ur depositing debug statements in code to check if the expression is > still there. I still fail to see why u can't just *look* at your code and see > if ur using the value or not. You can certainly try to do that, but it may be difficult. If you have a function f with argument a, and an application (f a) is an argument of a function g, .... it isn't so easy to determine that the final result of your program actually depends on the value of a: the result of f applied to a may be used by another application, but is its result used? Well if you have a fully lazy language, you can actually do an experiment which can positively say 'yes'. > Can I get an example? Hehe -- sure, download Felix and tell me if the 7'th argument to the 23'rd function in the module 'flx_inline' is 'used' :) [Arggg .. no don't actually do that .. you're supposed to just throw up your hands in horror and admit defeat :] > True, well almost true. The compiler can determine even in a strict language > if the value is used or not, using strictness analysis. So you could put > debugging statements in an expression and expect to see them and then volla, > do not. AHA! Can you?? Consider this: you aren't using an argument, so you optimise it away. Then you change the function so the argument is *conditionally* used -- but call it so the condition is never satisfied. OK, so you have a dumb analyser that can't tell the condition is never satisfied so it keeps the parameter -- and now suddenly the argument is eagerly evaluated. Problem is the argument was a division by zero. And a change in the function encoding with no impact on the result it returns suddenly never even gets entered (the program crashes before the function is called). This won't happen with a lazy language I think. I asked 'Can you??' above and really meant it: I'm actually inlining and optimising things in my compiler now and I'm just NOT sure what I can get away with and what I can't. However it seems to me at the moment, 'sloppy specification of evaluation order tending to laziness' actually allows more optimisation opportunties than either fully eager or lazy semantics. The problem is I don't know if you can still write enough useful deterministic programs with sloppy semantics or not..? [Felix doesn't allow side effects in functions BUT procedures can modify variables so the result of a function can vary depending on when it is called compared to any procedures hanging around ..] -- John Skaller, mailto:skaller@users.sf.net voice: 061-2-9660-0850, snail: PO BOX 401 Glebe NSW 2037 Australia Checkout the Felix programming language http://felix.sf.net ------------------- To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ Beginner's list: http://groups.yahoo.com/group/ocaml_beginners