![]() |
![]() |
|
![]() |
![]() |
Encyclopedia :
H :
HA :
HAS :
Haskell programming language |
|
|
Haskell programming languageHaskell is a standardized functional programming language with non-strict semantics, named after the logician Haskell Curry. It was created by a committee formed in the 1980s for the express purpose of defining such a language.The latest semi-official language standard is Haskell 98, intended to specify a minimal, portable version of the language for teaching and as a base for future extensions. The language continues to evolve rapidly, with Hugs and GHC (see below) representing the current de facto standard. Interesting Haskell features include support for recursive functions and datatypes, pattern matching, list comprehensions and guard statements. There is also a Haskell-like language that offers a new method of 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. For more comprehensive information, see the haskell.org website, linked at the end of this article. ExamplesThe 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 fac n = product [1..n] A naïve 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@(_:rest) = 0 : 1 : (zipWith (+) fibs rest)
The previous function creates an infinite list, which is possible because of lazy evaluation. fib n = fibs !! n
( The Quicksort algorithm can be elegantly expressed in Haskell with the help of list comprehensions: qsort [] = [] qsort (pivot:tail) = qsort left ++ [pivot] ++ qsort right where left = [y | y <- tail, y < pivot] right = [y | y <- tail, y >= pivot] (Note that because of excessive copying and concatenation of lists this code can be rather slow, depending on the implementation.) A remarkably concise function that returns the list of Hamming numbers in order: hamming = 1 : map (*2) hamming # map (*3) hamming # map (*5) hamming
where xxs@(x:xs) # yys@(y:ys)
| x==y = x : xs#ys
| x
|
|
|
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License. |
|
| © 2008 Chamas Enterprises Inc. |