Encyclopedia > Haskell programming language

  Article Content

Haskell programming language

In the 1980s, a committee was formed to create a standardized functional programming language with lazy evaluation. Haskell, named after the logician Haskell Curry, was the result of those deliberations. The latest version of the language is Haskell 98.

Some Haskell features are extremely simple recursion, pattern matching, list comprehensions, making difficult functions in other procedural languages almost trivial in Haskell. Haskell is, as of 2002, the functional language on which the most research is being performed. Several variants have been developed: parallelizable versions from MIT and Glasgow, both called Parallel Haskell, more parallel and distributed versions called Goffin and Eden, an eager version called Eager Haskell and several object oriented versions: Haskell++, O'Haskell and Mondrian.

There is also a Haskell-like language that offers support for GUI development called Concurrent Clean. Its biggest deviation from Haskell is in the use of Uniqueness types for input as opposed to Monads.

An educational version of Haskell called Gofer was developed by Mark Jones. It was supplanted by HUGS, the Haskell User's Gofer System (see the Implementations section of this article).

For more comprehensive information, see the haskell.org website, linked at the end of this article.

Examples The classic definition of the factorial function:
fac 0 = 1
fac n = n * fac (n - 1)

The cute definition of the factorial function (using a built-in Haskell list notation and the standard product function):
fac n = product [1..n]

A naive implementation of a function which returns the nth number in the Fibonacci sequence:
fib 0 = 0
fib 1 = 1
fib n = fib (n - 2) + fib (n - 1)

A function which returns a list of the Fibonacci numbers in linear time:
fibs = 0 : 1 : (zipWith (+) fibs (tail fibs))

The previous function creates an infinite list, which is possible because of lazy evaluation. One could implement fib as:
fib n = fibs !! n
(!! is an operator which gets the nth element of a list).

The Quicksort alogrithm can be elegantly expressed in Haskell with the help of list comprehensions:
qsort []     = []
qsort (x:xs) =
  qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
  where
    elts_lt_x   = [y | y <- xs, y < x]
    elts_greq_x = [y | y <- xs, y >= x]

Implementations The following all comply (or very nearly comply) with the Haskell 98 standard, and are distributed under open source licences. There are currently no commerical Haskell implementations.

  • Hugs (http://www.haskell.org/hugs/[?]) is a bytecode interpreter. It offers fast compilation of programs and reasonable execution speed. It also comes with a simple graphics library. Hugs is good for people learning the basics of Haskell, but is by no means a "toy" implementation.
  • GHC (http://www.haskell.org/ghc/[?]). The Glasgow Haskell Compiler compiles to native code on a number of different architectures, and can also compile to C. GHC is probably the most popular Haskell compiler, and there are quite a few useful libraries (e.g. bindings to OpenGL) that will only work with GHC.
  • nhc98 (http://www.cs.york.ac.uk/fp/nhc98/[?]) is another bytecode compiler, but the bytecode runs significantly faster than with Hugs. Nhc98 focuses on minimising memory usage, and is a particularly good choice for older, slower machines.
  • HBC is another native-code Haskell compiler. It hasn't been actively developed for some time, but is still usable.

External links



All Wikipedia text is available under the terms of the GNU Free Documentation License

 
  Search Encyclopedia

Search over one million articles, find something about almost anything!
 
 
  
  Featured Article
DB

... maker; see DB (car) DB is the abbreviation for Deutsche Bahn, the major German railway company DB is the abbreviation of Dominion Breweries[?], a major beer brewing ...

 
 
 
This page was created in 117.8 ms