caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Pierre Weis <pierre.weis@inria.fr>
To: "Daniel Bünzli" <daniel.buenzli@epfl.ch>
Cc: caml-list@inria.fr
Subject: Re: lazyness in ocaml (was : [Caml-list] kprintf with user formatters)
Date: Thu, 22 Jul 2004 18:28:51 +0200	[thread overview]
Message-ID: <20040722182851.B18239@pauillac.inria.fr> (raw)
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

> 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] <http://doi.acm.org/10.1145/944705.944727>

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


  reply	other threads:[~2004-07-22 16:28 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-30 16:32 [Caml-list] kprintf with user formatters Damien
2004-07-14 21:10 ` Pierre Weis
2004-07-15  0:17   ` Markus Mottl
2004-07-15  7:30     ` David MENTRE
2004-07-15  7:59       ` Jean-Christophe Filliatre
2004-07-15 23:35         ` henri dubois-ferriere
2004-07-15  7:39     ` Damien
2004-07-15 12:19       ` Markus Mottl
2004-07-15 12:42         ` Basile Starynkevitch [local]
2004-07-15 13:45           ` Markus Mottl
2004-07-15 14:22             ` Basile Starynkevitch [local]
2004-07-15 14:57               ` Markus Mottl
2004-07-16  6:47               ` Pierre Weis
2004-07-16  7:13                 ` Jean-Christophe Filliatre
2004-07-16  7:23                   ` henri dubois-ferriere
2004-07-16  7:44                     ` Jean-Christophe Filliatre
2004-07-16 17:56                   ` Markus Mottl
2004-07-19  9:17                   ` Pierre Weis
2004-07-19  9:32                     ` Jean-Christophe Filliatre
2004-07-16  7:21                 ` henri dubois-ferriere
2004-07-16 17:44                 ` Markus Mottl
2004-07-19 10:10                   ` Pierre Weis
2004-07-19 10:43                     ` Jon Harrop
2004-07-21 15:52                       ` Pierre Weis
2004-07-21 17:43                         ` lazyness in ocaml (was : [Caml-list] kprintf with user formatters) Daniel Bünzli
2004-07-22 16:28                           ` Pierre Weis [this message]
2004-07-22 17:03                             ` William Lovas
2004-07-22 23:00                             ` skaller
2004-07-23  3:32                               ` William Lovas
2004-07-28  7:26                               ` Pierre Weis
2004-07-28  8:06                                 ` skaller
2004-07-28  8:29                                   ` Daniel Bünzli
2004-07-28  9:13                                   ` Pierre Weis
2004-07-28  9:36                                     ` skaller
2004-07-28  9:38                                     ` skaller
2004-07-28 10:17                                 ` Jason Smith
2004-07-28 12:31                                   ` skaller
2004-07-21 20:41                         ` [Caml-list] kprintf with user formatters Jon Harrop
2004-07-22 15:39                           ` Pierre Weis
2004-07-22 22:16                             ` [Caml-list] lazy evaluation: [Was: kprintf with user formatters] skaller
2004-07-22 22:42                             ` [Caml-list] kprintf with user formatters skaller
2004-07-22  8:05                         ` [Caml-list] wait instruction lehalle@miriad
2004-07-22  8:40                           ` Olivier Andrieu
2004-07-22 10:35                             ` lehalle@miriad
2004-07-22 10:33                           ` Vitaly Lugovsky
2004-07-16  6:17             ` [Caml-list] kprintf with user formatters Pierre Weis
2004-07-16 17:14               ` Markus Mottl
2004-07-19 10:00                 ` Pierre Weis
2004-07-16  6:02       ` Pierre Weis
2004-07-16  8:42         ` Damien
2004-07-19  9:00           ` Pierre Weis
2004-07-16 16:52         ` Markus Mottl
2004-07-19  9:28           ` Pierre Weis
2004-07-15 22:20     ` Pierre Weis
2004-07-15 23:01       ` Markus Mottl
2004-07-16 16:17     ` james woodyatt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040722182851.B18239@pauillac.inria.fr \
    --to=pierre.weis@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=daniel.buenzli@epfl.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).