[Haskell-cafe] Re: New slogan for haskell.org

Yitzchak Gale gale at sefer.org
Thu Nov 29 18:45:16 EST 2007

I wrote:
>> Python's "iterators" are not the same as iterators in C
>> and other older languages. They are lazy lists. The reason
>> they named them "iterators" is not to scare people.

>> Haskell was not the first to have lazy lists, but Haskell
>> was an important part of the inspiration for introducing
>> them into Python.

Jerzy Karczmarczuk wrote:
> Actually, I would *sincerely* like to see some reference proving that.

The Python Library Reference, "itertools" (section 6.5 in Python 2.5):
"This module implements a number of iterator building blocks inspired
by constructs from the Haskell and SML programming languages.
Each has been recast in a form suitable for Python."

> I cite Guido V.R., 2005:
>  "About 12 years ago, Python aquired lambda, reduce(), filter() and
>   map(), courtesy of (I believe) a Lisp hacker who missed them and
>   submitted working patches."
> (http://www.artima.com/weblogs/viewpost.jsp?thread=98196)

OK. Haskell also got those from Lisp, ultimately.

> Give to Caesar...: It was Amrit Prem; one history page on WP says that
> no specific mention of any Lisp heritage is mentioned in the release
> notes at the time, so all speculations are still possible...

OK. (That is a quote from Wikipedia, yes?)

> But, in fact, Python iterators - in general - are neither lazy nor lists.
> No linking!

True, they are not implemented as linked lists, like
in Lisp-family languages. They have semantics
similar to a thunk, and the syntax of the language
encourages their use for iteration over a sequence;
so in practical use, they provide a "feel" very
similar to one of the most common uses of
lazy lists in Haskell: they allow you to iterate
over a sequence without specifying
whether or not it has already been computed.

(Alright, I should have said "non-strict".)

> They are syntactic shortcuts to *objects* possessing the method 'next'.
> So, there is no call by need, no updated thunks, etc. Calling them lazy
> is an abuse of the language, although quite intuitive. I don't want to raise
> a war about that...

Agreed, they are not *really* thunks, they just intuitively
feel very like them. The "next method" trick is a perversely
cute way of achieving that in a strongly imperative
call-by-(value/reference) language.

The use of "iterable" in "for x in iterable:" is effectively
call by need. itertools.tee() gives you updating thunks.

> The laziness, meant as deferred procedure calls *CAN* be used in Python,
> also in iterator context, through generators, that's true. But still there
> are no update'able automatically thunks, no lazy data! If generators remind
> me of something, it is co-routines.

Yes, they are becoming co-routines, you
can now send data back into them.

If I can put a lazy list comprehension in place of
a strict one, why is that not lazy data?

Look, I am not arguing that this pseudo-laziness
is a central feature of Python, or that Python is close
to being a functional language. I don't think
Henning meant to say that, either. But
there are some features like that, and they
are very nicely done, people like them.
Even before I knew about Haskell, those were
the features of Python that made me really
enjoy the language. So I agree with others
who wrote that pointing out beautiful
Haskell-inspired or Haskell-like features in
a person's current favorite language might be
a good way to encourage that person to have a look
at Haskell.

> BTW. The BDFL Van Rossum never said anything
> about "scaring". He said plainly that folds are things
> he *hates* most.

He hates them because there is another way to do
them in Python. The other way is "simpler"  - easier
to learn by the uninitiated - and more "Pythonic" -
fits in better with an overall consistent and intuitive
way of thinking when you write Python programs that
makes it easy to think of the right thing to do. People in this
thread are using the word "scary" to mean the opposite
of those things, so I am also using the word in
that way.

>> Guido was forced to do something - someone had written
>> a new Python interpreter, called "Stackless Python",
>> in which every Python function was a Scheme-like continuation.
>> People found this very, very scary. So Guido stopped
>> it by introducing laziness, which could be made much
>> less scary.

> Give to Caesar...
> Someone, was Christian Tismer:
> http://www.python.org/workshops/2000-01/proceedings/papers/tismers/spcpaper.
> htm

Very good, yes, thank you!

> and I am doubtful about the statement that people found it very, very scary.
> Simply they - usually - felt no *need* for another complication to learn,
> you know, *some* people are lazy... But Stackless still exists, GVR
> stopped nothing, and the Grant Olson's tutorial
> http://members.verizon.net/olsongt/stackless/why_stackless.html
> is really interesting

Indeed, thanks. But the efforts of Christian and others to push
Stackless into the mainstream of Python were not successful.
>From the "Acknowledgements" page of www.stackless.com:
"I would like to thank... (many people) ...and Guido van Rossum
for still not sending the Spanish Inquisition."


More information about the Haskell-Cafe mailing list