Haskell is a pure, lazy, strongly typed functional programming language. It was influenced by languages like Lisp, ML, and Miranda. There are two main implementations, GHC which compiles to native code, and Hugs which is a bytecode interpreter. Haskell avoids bugs through its purity, strong typing, conciseness, and memory management. It is used in industries like aerospace, finance, and web development for tasks like processing internet abuse complaints, programmatically manipulating code, and implementing mathematical models.
2. History
Lisp/Scheme ML/OCaml Miranda Haskell 98
1959 1979 1985 2003
functional static lazy
language typing evaluation
3. History
There are two main Haskell implementations:
▹ GHC. Probably the most popular, compiles to native code on a
number of different architectures.
▹ Hugs. It’s a bytecode interpreter and the most portable and
lightweight of the Haskell implementations.
4. Related languages
There are some languages inspired by Haskell:
▹ Different type system: Epigram, Agda.
▹ JVM-based: Frege, Jaskell.
▹ Other related languages: Curry.
▹ Testbed for many new ideas: Parallel Haskell, Eager Haskell,
Generic Haskell, O’Haskell, Hume, Scotch, Disciple...
5. haskell
Haskell is a pure functional language. It means that:
▹ Variables never change after definition.
▹ Functions don’t have side effects.
▹ Functions always return the same output given the same input.
6. haskell
What haskell offer to the programmer?
▹ Purity. It doesn’t allow any side-effects.
▹ Laziness (non-strict). Nothing is evaluated until it has to be evaluated.
▹ Strong static typing. The compiler automatically infers a precise type for
all values and it permits no implicit type conversions.
▹ Elegance. Stuff just work like you’d expect it to.
7. haskell and bugs
Haskell programs have fewer bugs because Haskell is:
▹ Pure. There are no side effects.
▹ Strongly typed. There can be no dubious use of types.
▹ Concise. Programs are shorter which make it easier to “take it all” at once.
8. haskell and bugs
Haskell programs have fewer bugs because Haskell is:
▹ High Level. Haskell programs most often reads out almost exactly like the
algorithm description.
▹ Memory Managed. There’s no worrying about dangling pointers, the
Garbage Collector takes care of all that.
▹ Modular. Haskell offers stronger and more “glue” to compose your
program from already developed modules.
9. haskell cons
Haskell has some disadvantages:
▹ Hard to learn and master. It’s even harder without a proper computer
science background.
▹ You can’t write haskell-like code in other programming languages.
▹ Lacks libraries and support from who mantain and improve them.
27. C
// To sort array a[] of size n: qsort(a,0,n-1)
void qsort(int a[], int lo, int hi)
{
int h, l, p, t;
if (lo < hi) {
l = lo;
h = hi;
p = a[hi];
do {
while ((l < h) && (a[l] <= p))
l = l+1;
while ((h > l) && (a[h] >= p))
h = h-1;
if (l < h) {
t = a[l];
a[l] = a[h];
a[h] = t;
}
} while (l < h);
a[hi] = a[l];
a[l] = p;
qsort( a, lo, l-1 );
qsort( a, l+1, hi );
}
}
31. Haskell
pattern
matching fac 0 = 1
fac n | n > 0 = n * fac (n-1)
fac n = product [1..n]
fac n = foldr1 (*) [1..n]
fac n = if n == 1 then 1 else n * fac (n-1)
32. Haskell
fac n = case n of
0 -> 1
n -> n * fac (n-1)
facs = scanl (*) 1 [1..]
fac n = facs !! n
33. haskell in industry
Haskell is used in many areas:
▹ Aerospace, defense, finance, web startups, and hardware design
firms.
34. haskell in industry
automate processing procedural city generation
of internet abuse complaints and simulation market
programmatically analysis of cryptographic
manipulating a PHP code base protocols
35. haskell in industry
measure the counterparty risk on implement mathematical
portfolios of financial derivates models and other complex
job scheduling and brand handwriting recognition
matching system
36. Haskell
being lazy with class
Links:
http://haskell.org/ - Haskell official homepage
http://youtu.be/cXY4fSA7DnM - Stanford Tutorial
http://haifux.org/lectures/173/ - An overview of Haskell (Haggai Eran)
http://en.wikipedia.org/wiki/Haskell_(programming_language) - Haskell History
Tiago Babo
PPRO@FEUP 2012