See Iavor Diatchki’s page “The Evolution of a Programmer” for the “original” (though he is not the author), and also below for the story behind this version.

(This page has been translated into the Serbo-Croatian language by Anja Skrba from Webhostinggeeks.com. Thanks, Anja, for all your hard work!)

Freshman Haskell programmer

fac n = if n == 0 
           then 1
           else n * fac (n-1)

Sophomore Haskell programmer, at MIT

fac = (\\(n) ->
        (if ((==) n 0)
            then 1
            else ((*) n (fac ((-) n 1)))))

Junior Haskell programmer

fac  0    =  1
fac (n+1) = (n+1) * fac n

Another junior Haskell programmer

fac 0 = 1
fac n = n * fac (n-1)

Senior Haskell programmer

fac n = foldr (*) 1 [1..n]

Another senior Haskell programmer

fac n = foldl (*) 1 [1..n]

Yet another senior Haskell programmer

-- using foldr to simulate foldl

fac n = foldr (\\x g n -> g (x*n)) id [1..n] 1

Memoizing Haskell programmer

facs = scanl (*) 1 [1..]

fac n = facs !! n

Pointless (ahem) “Points-free” Haskell programmer

fac = foldr (*) 1 . enumFromTo 1