Revision 10 as of 2004-11-23 16:07:03

Clear message

Haskell

Haskell is a very modern functional language. It is used for some "real" projects (not just an experiment language) but is uncommon in industry. More information can be found at http://www.haskell.org/. (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 lazy (evaluate by need), functional (no assignments or side-effects) language. It supports parametric polymorphism (ala C++ templates), and ad-hoc polymorphism through type classes (ala Java Interfaces). Python offers the programmer a profusion of styles, including procedural, functional, and object-oriented. Lazy programming can be accomplished using generators and itertools. 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. Haskell supports procedural programming through monads (from category theory) which are also Haskell's interface to the world of side effects (e.g. graphics, file systems, sockets, etc.). However, imperative programming is neither Haskell's intention nor strength.

Compiled vs Interpreted:

Python's primary implementation is an interpreter. Haskell has a handful of implementations, including an interpreter (hugs) and some native-code compilers (ghc, nhc98). The biggest difference that this makes is in execution speed. When compiled, Haskell is surprisingly fast (surprising to those who think non-comercial languages are necessarily slowpokes), while nearly all Python programmers suggest that python is 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 "static typing done right" because it has type inference. Usually, type declarations are optional because the compiler is smart enough to figure out the type for you.

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.

Significant Whitespace:

Both use indentation as syntax.

Learning Curve:

Haskell has a much steeper learning curve for programmers who are not used to functional programming.

Contributors: MichaelChermside

See also [LanguageComparisons].

Unable to edit the page? See the FrontPage for instructions.