Why Haskell is cool (again)

Why Haskell is cool (again). Over a year ago I was mucking around Haskell but didn’t get deeply into it. Today I picked it up again, and while playing around with tutorials did something which, in my geeky way, I find cool.

With four lines of code, and with no more knowledge than a beginner has, I was able to calculate 10000 factorial. (For my non-mathsy readers, that is, 10000 times 9999 times 9998 times 9997 … times 3 times 2 times 1).

This is a Very Big Number (it’s here if you don’t believe me), and until today I haven’t come across a programming language which can even represent/work with anything this large “out of the box”. I’m sure there are other languages which can – I just haven’t met them. It’s interesting.

It took about seven seconds to work it out. Nifty.

2 Responses to “Why Haskell is cool (again)”

  1. January 14th, 2005 | 3:37 pm

    This can also be done with just a single line (if you don’t count the signature):
    fac :: Integer -> Integer
    fac n = product [1..n]
    Admittedly this relies on the product function being definie in Prelude, but it’s cool nonetheless :)

  2. Peter Scott
    June 4th, 2005 | 11:20 pm

    You can do in in Common Lisp with something like this:

    (defun factorial (n)
    (if (< n 2) 1 (* n (factorial (1- n)))))

    Really, bugnum support is nice but it shouldn’t be the big thing in a language.