caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Marius Nita <marius@cs.pdx.edu>
To: Jonathan Roewen <jonathan.roewen@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] lazy lists
Date: Fri, 26 Aug 2005 03:56:42 -0700	[thread overview]
Message-ID: <430EF56A.1030703@cs.pdx.edu> (raw)
In-Reply-To: <ad8cfe7e05082516566803c65a@mail.gmail.com>

Jonathan Roewen wrote:
> Hi,
> 
> Is the underlying implementation of the builtin lists in OCaml lazy?
> If not, is performance the reason for them not being lazy? I think
> lazy lists are a very strong point of Haskell, and am wondering if
> there's a lazy list implementation with all the standard list
> operations in the case that lists aren't lazy in OCaml.
> 
> Also, if they aren't, can someone give me some insight into the
> reasons INRIA chose not to?

It's not just a question of the "underlying implementation." OCaml and
Haskell use the same list definition:

   type 'a list = Cons of 'a * 'a list | Nil

but in Haskell it is lazy due to Haskell's lazy evaluation semantics.
OCaml has a strict evaluation semantics, so its lists, as defined above,
are strict.

If OCaml had chosen to implement lists lazily "behind the scenes," this
would be easily observable (and very counter-intuitive!) due to OCaml's
imperative features:

   let f _ = 5
   in f [print_string "calling f\n"]

would produce no output.

The good news is that you can define your own lazy data structures
pretty easily. OCaml offers the Lazy module, which makes working with
lazy suspensions easier.

	marius


  reply	other threads:[~2005-08-26 10:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-08-25 23:56 Jonathan Roewen
2005-08-26 10:56 ` Marius Nita [this message]
2005-08-26 11:04 ` Richard Jones
2005-08-26 11:16   ` Jun Mukai
  -- strict thread matches above, loose matches on Subject: below --
2007-05-01 14:10 Yitzhak Mandelbaum
2007-05-01 15:47 ` [Caml-list] " Loup Vaillant
2007-05-01 19:43   ` Jon Harrop
2007-05-02  7:16     ` Nicolas Pouillard
2007-05-02 10:03       ` Loup Vaillant
2007-05-02 10:15         ` Daniel de Rauglaudre
2002-07-03  9:45 Michael Vanier
2002-07-03 22:04 ` Remi VANICAT

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=430EF56A.1030703@cs.pdx.edu \
    --to=marius@cs.pdx.edu \
    --cc=caml-list@inria.fr \
    --cc=jonathan.roewen@gmail.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).