Needless copying in iterations?

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Sun Sep 16 16:45:12 CEST 2007


On Sun, 16 Sep 2007 13:31:57 +0000, Steven D'Aprano wrote:

> On Sun, 16 Sep 2007 10:58:07 +0000, Marc 'BlackJack' Rintsch wrote:
> 
>> On Sun, 16 Sep 2007 09:50:39 +0000, Steven D'Aprano wrote:
>> 
>>> The point is rather moot, since CPython (and probably other Pythons) do
>>> almost no optimizations. But just because Python is a dynamic language
>>> doesn't mean there are no optimizations possible: Haskell is a dynamic
>>> language, and there are optimizing compilers for it. Of course, it is
>>> much simpler for Haskell, because of the type system it uses.
>> 
>> What do you mean by Haskell is a dynamic language?  It is statically and
>> strict typed and the compiler usually knows all the functions.  No
>> "surprises", no side effects, no duck typing.
> 
> Haskell's IO monad (and possibly the do monad?) allows side effects. It 
> would be a pretty poor programming language that didn't allow input or 
> output!

Those side effects stay in the IO monad and don't "leak" into other areas
so the compiler still knows much more about the possible data flow than
the compilers of most other languages.

> Haskell uses type inference, and has a "maybe" type for those cases where 
> it can't tell what the type will be.

Haskell is statically typed, the compiler must know the type of every name
otherwise it stops with an error message.  The `Maybe` type is for
functions that may return something (typed) or `Nothing`.  For example a
`lookup` function can have the signature:

lookup :: Eq a => a -> [(a,b)] -> Maybe b
lookup key assocList = ...

The compiler infers the concrete types of `a` and `b` at compile time.

> If you still don't accept that Haskell is a dynamic language, for 
> whatever definition of dynamic language you use, I'll withdraw the claim 
> for the sake of not getting bogged down in long arguments over something 
> that was really just a minor point.

You said it must be possible to optimize a dynamic language because there
are optimizing compilers for a dynamic language like Haskell.  That's a
minor point now?

The main problem with optimizing Python code is that the language is
dynamically typed -- the types of objects bound to names are only checked
at runtime and can change at nearly every point in time while executing.
Haskell is statically typed, the types are all inferred at compile time so
it's possible to optimize the code for those types.  The compiler knows
the exact type of every name.  By what definition is that a dynamic
language!?

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list