caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Florian Weimer <fw@deneb.enyo.de>
To: Dario Teixeira <darioteixeira@yahoo.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Purity and lazyness
Date: Fri, 07 Jan 2011 20:17:32 +0100	[thread overview]
Message-ID: <87vd20plpv.fsf@mid.deneb.enyo.de> (raw)
In-Reply-To: <699537.6718.qm@web111509.mail.gq1.yahoo.com> (Dario Teixeira's message of "Fri, 7 Jan 2011 07:35:44 -0800 (PST)")

* Dario Teixeira:

> So, my question is whether there is something I'm missing and in fact "purity 
> <=> lazyness", or I am reading too much from those Haskeller presentations,
> because they never meant to say anything beyond "lazyness => purity", and
> freely mixing the two was just a casual oversight.

As specified, Haskell is not a pure language because every pattern
match can have side effects.  The Haskell community is split between
those who think that this is a good thing, and those that consider it
problematic.  (Obviously, there is a large pure subset, much more
useful than Erlang's pure subset and covering almost the whole
language; you just avoid lazy I/O and use unsafePerformIO only for
correcting the type of functions imported through FFI.)

In my very limited experience, there are two kinds of laziness:
essential laziness and laziness for presentation purposes.

Essential laziness occurs when you construct values which would not
otherwise be possible to construct in a pure language.  For instance,
if you have got some sort of compiler, at one point, you might want to
perform name resolution.  At that point, you want to translate names
(references) to the program entities they denote (referents).  In
general, these references do not form a tree (for instance, a function
body can refer to another function by name, which refers to the
original function).  With laziness, you can compute a map from names
to entities, and the entities use this maps to resolve the names they
use as references.  Name lookup is only performed once per name.
Without laziness, you have to perform name lookup each time you follow
a reference because the self-referential nature of the data structure
cannot be reflected in the program.

The other type of laziness occurs when you write programs which work
on large (perhaps even infinite) data structures, and carefully look
only at the parts you need.  This can lead to notationally elegant
programs, but you have to be extremely careful not to keep references
to parts you no longer need, otherwise your program will require too
much memory (the live set might even be unbounded).  Space retention
behavior is quite implementation-dependent, too.

It bothers me a bit that you cannot tell the first form from second
just by looking at the types.  You just don't know if the data
structure is bounded or not.

  parent reply	other threads:[~2011-01-07 19:17 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-01-07 15:35 Dario Teixeira
2011-01-07 16:07 ` Damien Doligez
2011-01-07 16:38   ` David Rajchenbach-Teller
2011-01-07 18:16     ` Holger Weiß
2011-01-07 20:22     ` Eray Ozkural
2011-01-07 20:29       ` orbitz
2011-01-07 20:30         ` Joel Reymont
2011-01-07 20:33         ` Eray Ozkural
2011-01-08  9:44     ` Jesper Louis Andersen
2011-01-07 17:21 ` Alain Frisch
2011-01-07 17:46   ` Christophe Raffalli
2011-01-07 18:11 ` Holger Weiß
2011-01-07 18:52   ` Brian Hurt
2011-01-07 19:32     ` Petter Urkedal
2011-01-07 20:25     ` Eray Ozkural
2011-01-09 16:11     ` Jon Harrop
2011-01-10  6:27       ` Eray Ozkural
2011-01-07 19:17 ` Florian Weimer [this message]
     [not found]   ` <AANLkTikxCSQ+0XkOmSVDb3EWq_2oQ0pac3bDgc7f7jq+@mail.gmail.com>
2011-01-07 20:52     ` bluestorm
2011-01-09 16:15       ` Jon Harrop
2011-01-08  0:26   ` Elias Gabriel Amaral da Silva
2011-01-08  9:28     ` Christophe Raffalli
2011-01-08 22:47     ` Florian Weimer
2011-01-09 10:00       ` Petter Urkedal

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=87vd20plpv.fsf@mid.deneb.enyo.de \
    --to=fw@deneb.enyo.de \
    --cc=caml-list@inria.fr \
    --cc=darioteixeira@yahoo.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).