Haskell programming language |
Haskell is a standardized purely functional functional_programming programming language with non-strict programming language. Named after the logician Haskell Curry, it was created by a committee formed in 1987 for the express purpose of defining such a language. The direct predecessor of Haskell was Miranda programming language from 1985. 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 Glasgow Haskell Compiler (see below) representing the current de facto#De facto standards.
Characterizing syntax features in Haskell include pattern matching, currying, list comprehensions, guard (computing)s, and definable operator (programming)s. The language also supports recursive functions and algebraic data types, as well as lazy evaluation. Unique concepts include Monads_in_functional_programmings, and type classes. The combination of such features can make function (programming) which would be difficult to write in a procedural programming language almost trivial to implement in Haskell.
The language is, as of .
Although Haskell has a comparatively small user community, its strengths have been well applied to a few projects. Autrijus Tang s Pugs is an implementation for the forthcoming Perl 6 language with an interpreter and compilers that proved useful already after just a few months of its writing. DARCS is a revision control system, with several innovative features.
There is also a Haskell-like language that offers a new method of support for GUI development called Clean programming language. Its biggest deviation from Haskell is in the use of uniqueness types for input as opposed to Monads in functional programming.
= Examples =
== Anatomy of a Haskell function ==
The Hello world program of functional languages is the factorial function. Expressed as pure Haskell:
fac :: Integer -> Integer fac 0 = 1 fac n |(n > 0) = n * fac (n-1)
This describes the factorial as a recursive function, with a single terminating base case. It is similar to the descriptions of factorials found in mathematics textbooks. Much of Haskell code is similar to mathematics in facility and syntax.
The first line of the factorial function shown is optional, and describes the types of this function. It can be read as the function fac (fac) has type (::) from integer to integer (Integer -> Integer). That is, it takes an integer as an argument, and returns another integer.
The second line relies on pattern matching, an important part of Haskell programming. Note that parameters of a function are not in parentheses but separated by spaces. When the function s argument is 0 (zero) it will return the integer 1 (one). For all other cases the third line is tried. This is the Recursion, and executes the function again until the base case is reached. A guard (computing) protects the third line from negative arguments that would run down unterminated.
The Prelude is a number of small functions analogous to C s standard library. Using the Prelude and writing in the point free (insert classic Haskell joke here) style of unspecified arguments, it becomes:
fac = product . enumFromTo 1
The above is close to mathematical definitions such as f = g o h (see function composition), and indeed, it s not an assignment of a value to a variable.
== More complex examples ==
A simple RPN calculator:
calc = foldl f [] . words where f (x:y:zs) + = y+x:zs f (x:y:zs) - = y-x:zs f (x:y:zs) * = y*x:zs f (x:y:zs) / = y/x:zs f xs y = (read y :: Float):xs
A function which returns a stream of the Fibonacci numbers in linear time:
fibs = 0 : 1 : (zipWith (+) fibs (tail fibs))
The same function, presented with GHC s parallel list comprehension syntax:
fibs = 0 : 1 : [ a+b | a|
|