Hacker News new | ask | show | jobs
by lutusp 4854 days ago
Java can produce any result that Haskell can produce. End of story, full stop. All non-broken computer languages are Turing machines.

This is not to suggest that someone would want to use Java for anything sufficiently sophisticated, unless one is a masochist, but then, that wasn't your claim.

> As far as I'm aware in Java, there's no way to write a function with a signature that says "Take two numeric arguments of any type". Certainly pre-generics, this is impossible.

A separate claim with no meaningful relation to the original one. This claim is that it would be inconvenient, not impossible.

3 comments

> Java can produce any result that Haskell can produce. End of story, full stop.

Yes, I'm not disputing this- I'm fully in agreement that all turing-complete languages can compute all turing-computable computations. I've never been trying to argue against that. I'm sorry if I haven't explained myself clearly enough- let me give it another shot.

In Haskell, I can write a function operating on numbers like this:

    f x = x**2 + x + 1
The AD library means I can do this:

    g = diff f
and g will behave as if I'd declared

    g x = 2 * x + 1
As far as I'm aware, it's not possible to write this code in Java- you can't get the differentiated version of a Java function this way.

You can compute the same results, of course. You just can't write a library that will accept a function and give back its differentiation.

You can write a function that takes some representation of a mathematical function, for example as a string, and build a function from that to compute the same results, but you can't pass in an actual Java function- so you can't write the library. You can write a library which differentiates string-representations-of-functions, but you can't write one that differentiates first-class-Java-functions (well, objects with functions on, but you get the idea. I hope.)

> As far as I'm aware, it's not possible to write this code in Java- you can't get the differentiated version of a Java function this way.

No. The algorithms for symbolic differentiation are well-known, they aren't unique to Haskell. They happen not to be present in any Java library AFAIK, but that's because no one is sufficiently masochistic to code them there.

(long pause ...)

Whoops -- I was wrong:

https://code.google.com/p/javacalculus/

> You can write a library which differentiates string-representations-of-functions, but you can't write one that differentiates first-class-Java-functions ...

I think we're getting into a moot area now. If the end result is symbolic differentiation, the specifics become irrelevant. And, since Java bytecode can be converted into a textual representation, it can also be symbolically differentiated by conventional means.

Also, we've left the original topic, which was that Haskell has properties not present in other languages and/or outcomes not possible in other languages.

In a larger sense, wouldn't it be more praiseworthy to say that Haskell does exactly what other languages do, but much better? That time spent programming in Haskell is more productive when measured by bug-free lines of code and concise expressions? Or that, when parallel processing finally arrives in full force, functional programming will not longer be optional?

> If the end result is symbolic differentiation (...)

Ah, I see the problem- automatic differentiation is not the same as symbolic differentiation- see wikipedia: http://en.wikipedia.org/wiki/Automatic_differentiation This certainly isn't a moot point :)

> Also, we've left the original topic (...)

No- again, I've been saying the same thing all along. In fact I'm only using Haskell as an example. There are things which cannot be expressed in Haskell, too- for example dependent typed programs as you might find in Agda or Idris.

> In a larger sense, wouldn't it be more praiseworthy to say that Haskell does exactly what other languages do, but much better?

This is a separate conversation entirely. My aim is not to "praise Haskell". I have used Haskell and Java only as examples.

There are completely reasonable languages (distinctly non-broken) that are not Turing complete like Coq and Agda. You can still use them to write interesting, non-trivial programs! In fact, their limitations aren't immediately obvious--the only interesting program it's obvious they can't write is an interpreter for themselves or another programming language at least as powerful.
> Java can produce any result that Haskell can produce. End of story, full stop.

But can average Java programmers produce any result that average Haskell programmers can produce? I'd bet they can't. Haskell programmers are self-selecting: if you can grasp Haskell and be productive in it then you are an elite programmer. Not so if you can grasp Java.

> if you can grasp Haskell and be productive in it then you are an elite programmer.

Somehow I knew this was where it was going.

> Not so if you can grasp Java.

Compared to a cabbage or a turnip? I've been told you can't teach calculus to a horse. Elitism is like an onion ... and feel free to imagine that tedious conversation.

This isn't really relevant to the thread of discussion.