# Haskell/Overview

Haskell is a standardized functional programming language with non-strict semantics. Haskell features include support for recursive functions, datatypes, pattern matching, and list comprehensions. By combining these features, functions that would be difficult to write in a procedural programming language are almost trivial to implement in Haskell. The language is, as of 2011, the functional language on and in which the most research is being performed.
The examples below give a taste of Haskell, oriented toward those familiar with other programming languages.

## Examples

The classic definition of the factorial function:
A cute definition using Haskell's built-in list notation and the standard product function:
Both definitions above should compile into the same efficient code via a smart compiler using equational reasoning.
A naive implementation of a function which returns the nth number in the Fibonacci sequence:
A function which returns a list of the Fibonacci numbers in linear time:
The previous function defines an infinite list, which is possible because of lazy evaluation.
One could implement fib as:
(!! is an operator which gets the nth element of a list).
The Quicksort algorithm can be expressed in Haskell concisely as:
(Note that, conventionally, quicksort swaps values in-place; however, since Haskell's lists are immutable, this requires values to be copied instead.)
Non-skipping stable merge sort is
where (.) is the function composition operator (h . g) x = h (g x) , (\x -> ...) is a lambda expression (a nameless function), and the predefined function until cond fun repeatedly applies a function fun until a condition cond is met; with where keyword introducing the local definitions showcasing the use of patterns (with (x:xs) matching a non-empty list with the head x and tail xs) and guards.
The Hamming numbers sequence is just
using sections (partially applied operators) and the built-in function map working with lists, whether finite or not, due to lazy (i.e. by-need ) evaluation. Also, enclosing function's name into back-quotes turns it into infix operator so that sub-expressions are automatically formed as if by placing parentheses appropriately, forming a nested expression, as in 2+3+5 --> ((2+3)+5) ; and a comment line is introduced by two dashes.
Finally, the infinite list of prime numbers by trial division is
or as unbounded incremental Sieve of Eratosthenes with ordered lists,
defining primes corecursively as natural numbers which are not multiples of primes. Or with arrays,

## It's not just for quicksort!

Haskell is also used to build "real world" programs, including graphical or web user interfaces. To get a taste of Haskell in the real world, check out web frameworks in Haskell and Haskell in industry articles on the Haskell wiki, or darcs, an advanced revision control system written in Haskell.

## Notes

* ↑ Based on crude Google Scholar "since 2010" queries – Haskell "functional programming": 2220, Scheme "functional programming": 1400, ML "functional programming": 1020, Lisp "functional programming": 779, OCaml "functional programming": 316, Scala "functional programming": 290, XSLT "functional programming":93, Clojure "functional programming": 76