caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: "Loup Vaillant" <loup.vaillant@gmail.com>
To: "Brian Hurt" <bhurt@janestcapital.com>
Cc: "Jon Harrop" <jon@ffconsultancy.com>, caml-list@yquem.inria.fr
Subject: Re: [Caml-list] Help me find this pdf
Date: Fri, 19 Oct 2007 15:49:47 +0200	[thread overview]
Message-ID: <6f9f8f4a0710190649x2ad33e26h3b1421a63df21780@mail.gmail.com> (raw)
In-Reply-To: <4718AA76.3010103@janestcapital.com>

2007/10/19, Brian Hurt <bhurt@janestcapital.com>:
> The only thing missing is some syntactic sugar to make the above pattern
> matching nicer- computationally, the same values will need to be forced.  If
> you're arguing in favor of the syntactic sugar, I'm sympathetic.  If you're
> arguing that the compiler could somehow avoid forcing the same
> values, I don't see how.

(Disclaimer: I suspect I'm a bit off-topic)
If we really want to, we can delay the evaluation at all costs, by
delaying even the car of the Cons cells

type 'a node_t =
    | Empty
    | Cons of 'a Lazy.t * 'a lazylist
and 'a lazylist = 'a node_t Lazy.t
;;

For instance, when figuring out if the list is empty or not, the first
element isn't forced. You can even force the second element of the
list without forcing the first:

match Lazy.force zlst with
  | Cons(_, tl) ->
    match Lazy.force tl with
      | Cons(hd, _) ->
        let head = Lazy.force hd in
          [...]
;;

Or, assuming I can get away with unsafe code:

let hd zlst = match Lazy.force zlst with
  | Cons(h, _) = h
;;
let tl zlst = match Lazy.force zlst with
  | Cons(_, t) = t
;;

(* and finally *)
match Lazy.force hd (tl zlst)
with [...]
;;

Well, I think this is overdoing laziness: more often than not, the
rest of a lazy list depends on the value of it's head (e.g. the list
of all integers, of a Fibonacci list). In such cases, doubling the
cost of laziness is worth nothing.

Regards,
Loup Vaillant


  reply	other threads:[~2007-10-19 13:49 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-18  9:52 Tom
2007-10-18 10:33 ` [Caml-list] " skaller
2007-10-18 11:01   ` Andreas Rossberg
2007-10-18 12:25 ` Jon Harrop
2007-10-18 12:40   ` Arnaud Spiwack
2007-10-18 13:17     ` Jon Harrop
2007-10-18 15:15       ` Till Varoquaux
2007-10-18 12:46   ` Jacques Garrigue
2007-10-18 13:57     ` Jon Harrop
2007-10-18 14:22       ` Brian Hurt
2007-10-18 14:52         ` Robert Fischer
2007-10-18 15:04           ` Eric Cooper
2007-10-18 17:18         ` Jon Harrop
2007-10-19  1:16           ` skaller
2007-10-19  5:09           ` Bárður Árantsson
2007-10-19  5:23             ` [Caml-list] " Erik de Castro Lopo
2007-10-19  5:46               ` Bárður Árantsson
2007-10-19 12:25               ` [Caml-list] " Christophe Raffalli
2007-10-19 12:47                 ` Luc Maranget
2007-10-20 14:26                   ` Christophe Raffalli
2007-10-19 14:48                 ` Robert Fischer
2007-10-19 21:43                   ` Andreas Rossberg
2007-10-19 21:51                     ` Robert Fischer
2007-10-20 13:10                       ` Andreas Rossberg
2007-10-19 23:10                     ` Jon Harrop
2007-10-20  1:13                       ` skaller
2007-10-20  6:36                         ` Tom
2007-10-21 11:17                           ` skaller
2007-10-19  8:55             ` Zheng Li
2007-10-19 22:27             ` [Caml-list] " Jon Harrop
2007-10-19 13:00           ` [Caml-list] " Brian Hurt
2007-10-19 13:49             ` Loup Vaillant [this message]
2007-10-19 14:41               ` Zheng Li
2007-10-19 23:09             ` [Caml-list] " Jon Harrop
2007-10-18 20:07   ` Tom
2007-10-19  0:59     ` skaller
2007-10-18 20:48 ` Lauri Alanko

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=6f9f8f4a0710190649x2ad33e26h3b1421a63df21780@mail.gmail.com \
    --to=loup.vaillant@gmail.com \
    --cc=bhurt@janestcapital.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=jon@ffconsultancy.com \
    /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).