Original Post

NON-EXISTING!
Join Date: Feb 2011
Just thought I'd put this here. It's a quick comparison between equivalent pieces of Haskell and C++ code.

``````qsort []     = []
qsort (x:xs) = qsort less ++ [x] ++ qsort more
where less = filter (<x)  xs
more = filter (>=x) xs``````

C++ code:
``````
template <typename T>
void qsort (T *result, T *list, int n)
{
if (n == 0) return;
T *smallerList, *largerList;
smallerList = new T[n];
largerList = new T[n];
T pivot = list[0];
int numSmaller=0, numLarger=0;
for (int i = 1; i < n; i++)
if (list[i] < pivot)
smallerList[numSmaller++] = list[i];
else
largerList[numLarger++] = list[i];

qsort(smallerList,smallerList,numSmaller);
qsort(largerList,largerList,numLarger);

int pos = 0;
for ( int i = 0; i < numSmaller; i++)
result[pos++] = smallerList[i];

result[pos++] = pivot;

for ( int i = 0; i < numLarger; i++)
result[pos++] = largerList[i];

delete [] smallerList;
delete [] largerList;
};
``````

As you can see, the Haskell version is far shorter. It's also prettier and easier to understand.

Elitist
Join Date: Aug 2008

Elitist
Join Date: Aug 2009
So, someone teach me haskell, if it has the same functions as C++.

NON-EXISTING!
Join Date: Feb 2011
What do you mean by 'the same functions'?

Elitist
Join Date: Aug 2009
Like C++ can made for all platforms, by just putting in the code.
How do it we it for haskell, etc.
I am trying to learn it btw.

NON-EXISTING!
Join Date: Feb 2011
Google GHC. It's the all-round best compiler and comes with an interpreter.

Elitist
Join Date: Aug 2009
Oh thanks.

not a super moderator anymore ;o
Join Date: Nov 2009
What exactly is this program supposed to do?

Hey look more than two lines.

NON-EXISTING!
Join Date: Feb 2011
Goodness me, Boredpayne.
I'm disappointed. :D

not a super moderator anymore ;o
Join Date: Nov 2009
Undeleting my post is soooo uncool.