Just sharing some of my inconsequential lunch conversations with you... RSS  

Sunday, September 30, 2007

Haskell vs C

in: haskell.org

3.1 Quicksort in Haskell

qsort []     = []
qsort (x:xs) =
qsort (filter (< x) xs) ++ [x] ++
qsort (filter (>= x) xs)

NOTE: I've broken into 4 lines because of my blog template limitations.

3.2 Quicksort in C
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);

t = a[l];
a[l] = a[hi];
a[hi] = t;

qsort( a, lo, l-1 );
qsort( a, l+1, hi );
}
}

Oops, is language evolution betting on the wrong branch?

1 comment:

André Cardoso said...

A very good interview with Simon Peyton Jones by Port25 is available at: http://port25.technet.com/archive/2007/09/26/haskell-in-the-hallway-sam-interviews-simon-peyton-jones.aspx

Development Catharsis :: Copyright 2006 Mário Romano