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 SAA22272; Thu, 22 Jul 2004 18:28:53 +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 SAA22215 for ; Thu, 22 Jul 2004 18:28:52 +0200 (MET DST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.12.10/8.12.10) with ESMTP id i6MGSpSH014872; Thu, 22 Jul 2004 18:28:51 +0200 Received: (from weis@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id SAA21462; Thu, 22 Jul 2004 18:28:51 +0200 (MET DST) Date: Thu, 22 Jul 2004 18:28:51 +0200 From: Pierre Weis To: =?iso-8859-1?Q?Daniel_B=FCnzli?= Cc: caml-list@inria.fr Subject: Re: lazyness in ocaml (was : [Caml-list] kprintf with user formatters) Message-ID: <20040722182851.B18239@pauillac.inria.fr> References: <200407211552.RAA04351@pauillac.inria.fr> <6DA682B9-DB3D-11D8-9D25-000393DBC266@epfl.ch> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Mailer: Mutt 1.0i In-Reply-To: <6DA682B9-DB3D-11D8-9D25-000393DBC266@epfl.ch>; from daniel.buenzli@epfl.ch on Wed, Jul 21, 2004 at 07:43:08PM +0200 X-Miltered: at concorde with ID 40FFEB43.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Loop: caml-list@inria.fr X-Spam: no; 0.00; pierre:01 weis:01 pierre:01 weis:01 lazyness:01 caml-list:01 kprintf:01 formatters:01 haskell:01 combinators:01 cluttering:01 expr:01 expr:01 thunk:01 lazyness:01 Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk > I agree. I once tried to port some haskell combinators [1] to ocaml. > However I had to stop since using them meant cluttering your code with > (lazy e) and lead to unreadable code. Yes using lazy all over the place is too much! That's why we had once in Caml some implicit way to denote lazy expressions, such as when applying a constructor or building a record. Lazy record fields or lazy constructors had to be declared when defining the type they belongs to; then their usage was implicitely lazy. For example, lazy integer lists were defined as: type llist = {lazy head : int; lazy tail : llist};; Now, {head = expr_head; tail = expr_tail} was automatically compiled as {head = lazy (expr_head); tail = lazy (expr_tail)} (with trivial optimisations if the lazy expressions are simple enough ({head = 1; ...} would build any lazy thunk)). Also an addition to the pattern matching algorithm allowed automatic forcing of lazy parts of data structures. This technic leads to simple and readable lazy programs. > A more lightweight notation would be needed in order to do real lazy > programming in ocaml. At that time I wondered if specifiying the > lazyness when one defines the function and not when one uses it would > be a problem (I mean a technical problem, not an ideological one). > For example if one defines > > let f (lazy x) = ... > > then the application f (x + y) would implicitely mean f (lazy (x + y)). That's a good idea, if only it were compatible with higher-order functionality (and modularity), which I don't know for sure. In my mind, this idea would be a type-based transformation of the source code. The typing rule for lazy function application would be: |~ -: (f : 'a lazy -> 'b) (e : 'a) ---------------------------------- (lazy app) |~ -: (f e : 'b) and the transformation rule on the type annotated abstract syntax trees would be: (f : 'a lazy -> b) (e : 'a) => (f : 'a lazy -> b) (lazy e : 'a lazy) Interestingly enough, the typing rule implies that you not only can omit the lazy keyword at application time: it would be mandatory to omit it! Weel, not so bad, after all ... This has to be precisely ruled out and the necessary proofs have to be made, but I think it could work (including for higher-order functional, map, fold, and so on). I mean, I don't see any trivial counter-example that would ruin this scheme. Wao! If this rule turned out to be usable, it would be a major improvement for lazy evaluation in our favorite language. > Alternatively something less intrusive than the keyword 'lazy' would be > good. > > Daniel > > [1] Right, but which one ? Best regards, Pierre Weis INRIA, Projet Cristal, http://pauillac.inria.fr/~weis ------------------- 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