[Haskell-beginners] My notes on a YouTube video presentation on Haskell

Costello, Roger L. costello at mitre.org
Sun Jun 5 16:35:22 CEST 2011


Hi Folks,

Here are my notes on a YouTube video on Haskell (http://www.youtube.com/watch?v=cXY4fSA7DnM)

If you wish to view the video, I recommend skipping over the first part. The Haskell presentation starts at 3:10

Here's what the speaker (Sasha Rush) says:

Haskell is an avant-garde programming language. It's not something that you will see a lot of companies using these days. If you want to get a job, you should be a really good C programmer. If you want to program the future, you should learn Haskell.

Haskell is fast like C. It's not as fast, but it's getting there. It on the same order of magnitude. Here's a comparison of the speeds of several languages:

(Optimized) Haskell is 1.5x slower than C
Schema 9.4x
Python 16x
PHP 23x
Ruby 57x

Let's take an example -- the Fibonacci sequence.

Recall that the Fibonacci sequence begins with the number 1, then another 1, then the following numbers are the sum of the previous two numbers:

1, 1, 2, 3, 5, 8, 13, 21, ...

Here's the Fibonacci sequence implemented in Java:

List <int> fib(int n) {
    List <int> seq = new ArrayList(n)
    seq[0] = 1;
    seq[1] = 1;
    for (int i = 2; i < n, i++) {
        seq[i] = seq[i-2] + seq[i-1];
    }
    return seq;
}

Read as: The function, fib, takes an integer, n, and returns a list of integers. First thing to do is to declare the list. Then set the first value, then the second value. Then do a for-loop.

Here's the Fibonacci sequence implemented in Haskell:

fib = 1 : 1 : zipWith (+) fib (tail fib)

Read as: The Fibonacci sequence is a list: the first item is the number 1, then the number 1, and then the following numbers are the zipping together (adding values at the same list position) of the Fibonacci sequence and the tail of the Fibonacci sequence. I created a graphic to illustrate:

http://www.xfront.com/Haskell/Fibonacci-Sequence-in-Haskell.png

/Roger




More information about the Beginners mailing list