Entry
How do Python and Haskell compare?
Jul 22nd, 2002 13:30
Michael Chermside,
(Please forgive or correct any errors here due to my not being very
familiar with Haskell.)
Haskell and Python are a somewhat odd pair to compare, because they are
so different in many ways. But what most users of both languages would
agree they DO share is a certain elegance of design.
Functional vs Procedural:
Haskell is a true functional language, while Python offers tools for
a profusion of styles, including procedural and object-oriented. Python
has some support for a functional style of programming, but the
profusion of side effects and the lack of tail recursion (elimination
thereof), make it an awkward style to use in Python. A procedural style
is nearly impossible to use in Haskell.
Compiled vs Interpreted:
Python is interpreted, while Haskell is compiled. The biggest
difference that this makes is in execution speed. Haskell is
surprisingly fast (surprising to those who think non-comercial languages
are necessarily slowpokes), while nearly all Python programmers suggest
that it's probably "fast enough", and that if it isn't, then the
critical sections should be re-written in C/C++.
Static vs Dynamic Typing:
Both Haskell and Python have strong (not weak) typing... instances
of a type can only be used as that type. But Haskell has static typing,
while Python has dynamic typing. This means that in Haskell, the type of
every expression and every variable is known at compile time (and
strictly enforced), while in Python expressions and variables don't even
HAVE a type (the objects they refer to have types, but that isn't known
until runtime). Since typing is such a fundamental part of Haskell (it's
part of what makes the language easy to reason about), this difference
is a fundamental one. However, for those python users who shudder to
think of typing "int i" before every variable use, take heart: Haskell
is often used as the example of "static typing done right", because it
has type inference... in most cases the compiler can figure out the type
for you, so declarations are ooptional, except where they carry actual
information.
There is also one similarity I feel compelled to point out:
List Comprehension Syntax:
Python's list comprehension syntax is taken (with trivial
keyword/symbol modifications) directly from Haskell. The idea was just
too good to pass up.