Haskell is a general purpose programming language for pure functional programming. It is named after the logician `Haskell Curry`_.

In September 1987, attendees at the conference on Functional Programming Language and Computer Architecture in Portland, Oregon discussed that idea that widespread use of functional programming languages was being hampered by the fact the lack of a common language; more than a dozen purely functional programming languages were made after the invention of Miranda. A committee was formed to design such a common language, providing faster communication of new ideas. The first version of Haskell was defined in 1990.

Its main implementation is the Glasgow Haskell Compiler (ghc), which was started by Kevin Hammond at the University of Glasgow in 1989. Later that year, the prototype was completely rewritten in Haskell by Cordelia Hall, Will Partain, and Simon Peyton Jones.


1   Syntax

Haskell inherited much of its syntax from Miranda.

2   Semantics

2.1   Operators


An infix operator for function application:

($) :: (a -> b) -> (a -> b)
($) = id

Unlike whitespace which has high precedence, $ has the lowest precedence.

It allows you to remove parentheses:

Prelude> (* 2) 1 + 1
Prelude> (* 2) $ 1 + 1
An infix operator for function composition. (g . h) x = g (h x)

2.2   Monads

2.2.1   Maybe

Monads can be folded:

> foldl (flip (:)) [] (Just 1)
> maybe [] (: []) (Just 1)

3   Tools

3.1   ghc

Some important options:

Turns on optimizations.
Ask the runtime system to gather memory and garbage performance numbers.

4   Profiling

Profiling proceeds in three steps: 1) compiling the program for profiling, 2) running it with particular profiling modes enabled, and 3) inspecting the resulting statistics.

To compile our program for basic time and allocation profiling, we use the -prof flag.

We also need to tell the profiling code which function we are interested in profiling. We do this by adding "cost centers" to them. A cost center is a location in the program we'd like to collect statics about. We can tell the compiler automatically insert the cost center on all top level functions for us by compiling with the -auto-all flag. Alternatively, cost centers can be manually added to instrument any expression using the SCC pragma:

mean :: [Double] -> Double
mean xs = {-# SCC "mean" #-} sum xs / fromIntegral (length xs)

Manual cost centers are a useful addition to automated cost center profiling, as once a hot spot has been identified, we can precisely pin down the expensive sub-expressions of a function.

5   Further reading

6   References

[1]Bryan O'Sullivan, Don Stewart, and John Goerzen. Chapter 25. Profiling and optimization. http://book.realworldhaskell.org/read/profiling-and-optimization.html