Hacker News new | ask | show | jobs
by drwh0 6400 days ago
haskell:

quicksort:

qsort [] = []

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

fib sequence:

fiblist = 0 : 1 : (zipWith (+) fiblist (tail fiblist))

but don't worry, with the rate at which the java kitchen sink swallows more paradigms, this will likely compile in java8 or something

4 comments

Except that this isn't really quicksort, because it's not in-place. Let's see you write the real one; I bet you it will be uglier than the equivalent java code.
Well, Java has Comparator classes. You can simply have first class functions by making a generic-d class (generic types for input and output), and a single member like "public T apply(F arg)". Its not that out of the ordinary.

So the paradigm is easily replicated, but yes, the syntax is totally ugly though ;) I think the real difficulty is in explaining how say lots of Comparators and Function classes are better or worse than a first-class function. Java at least affords type-safety on the wrapped functions whereas Ruby and Python don't (though, they don't really have any Java-style type safety to begin with).

You're right - Haskell does lazy evaluation far better than Lisp/Scheme do. I've been making my way through real world haskell, and I'm constantly amazed.

I'm not proficient enough in Haskell to write a public blog post on it though; and I figure Lisp was esoteric enough ;-)

Oh, they compile now. They're just ugly.

http://functionaljava.org/examples/1.5