ComparingFunctionalLanguages

ThoughtStorms Wiki

Quora Answer : How do different functional programming languages, such as Scala, Clojure, Haskell, and Lisp compare if you are to pick one to learn?

Apr 16, 2020

Scala isn't a "functional language". It's a generic language that can do functional stuff better than the previous generation.

My hunch is that Scala is going to lose ground to Swift and Kotlin in this space.

Haskell is the language to learn if you care about a) the more advanced theory of FP, and b) the most powerful features of type-systems. It's also a pretty great language for a bunch real applications these days. It won't hurt you at all to learn Haskell.

Lisp is a great language with a tonne of good ideas. Since forever. And you can't go wrong learning a Lisp.

But I personally, and yes, this is my bias, would recommend Clojure which is both

a) a Lisp (so has 90% of what's good about any Lisp), and

b) a proper hardcore functional programming language (ie. with immutability, default laziness for collections etc.) version of Lisp (unlike earlier Lisps which are mixed paradigm).

The other advantages of Clojure are that

c) like Scala it's designed to be compatible with the rest of the Java ecosystem, so you can immediately start doing real useful work with it in any context where you'd otherwise use Java

d) Also, in the browser, ClojureScript with Reagent (a React wrapper) makes writing browser-based UIs very civilized indeed,

e) is just a beautifully designed language in general. Clojure is as simple and "self evident" as a language like Python. Things generally just work as you'd expect (given the paradigm and the obvious quirks of Lisp syntax). But it's also more powerful and elegant than Python (code to do the same thing is both shorter and clearer)

So I love Clojure. It's not perfect. There are times it's not appropriate. But still I rank it as the best language I've ever met. And I would recommend it to anyone who wants to both develop their programming knowledge, and have a useful tool to do real work in.

Quora Answer : What programming language should I learn Scala or Haskell?

Nov 16, 2016

Haskell

It's principled and full of ideas. Scala is just a way of kludging those ideas onto a more traditional OO language.

If you need a beautifully designed functional language that's well integrated with Java, then use Clojure.

Quora Answer : Has Clojure missed a trick by not being more like Haskell, e.g., by allowing loops with mutable state or not doing type checking?

Thu

Clojure is immutable. And doesn't AFAICT have loops with mutable state.

Unless you are talking about the "loop" construct.

What the loop construct gives you is something half-way between a loop with mutable state. And the recursive way of iterating that FP languages normally use.

The reason for this is that Clojure uses ordinary method calls of the JVM as its function calls. It doesn't implement a Clojure VM on top of the JVM. The JVM doesn't have tail-call optimization (TCO) and because Clojure just uses ordinary method calls, it can't implement its own TCO.

So it creates a special "loop" construct which acts just like looping using recursion. But isn't "real" recursion. It's a different structure, dressed up to look and work as close to recursion as possible.

I actually prefer this to normal recursion and TCO, because it's explicit what you are doing. Whereas TCO is something you hope happens automatically when you write a recursive function; but if you mess up your function you end up with recursion without TCO and might crash the stack.

That's impossible with Clojure's "loop / recur"

Clojure's loop/recur though is not like an ordinary loop with a mutable variable either. Or if you see it like that, you have to accept that the mutability is significantly constrained, such that there is nothing to reason about beyond the reasoning you'd have to do in a genuine recursive function.

It's definitely not a case of "missing a trick". Even if you don't like Clojure's approach, it should be obvious that it's a necessary trade-off in order to get 99% of the benefits of immutability AND the benefit of being able to use Java's own methods and dispatch rather than implementing another layer of virtual machine.

The rejection of static typing is more of a free decision by Hickey. And I think he makes good points in his arguments against static types.

Personally, 95+% of the time I think Hickey is right. And maybe some non-trivial < 5% of the time I have a bout of wishing that there was some kind of extra compile time type constraint you could add to Clojure.

I understand how people could disagree. But it's an old argument. And certainly not mere "oversight" that Hickey missed out on a Haskell-like type-system.

(Also, I believe that this was NOT just because Lisp. Hickey was willing to break Lisp conventions when he thought he had a better idea. He didn't avoid a strong / static type system merely because other Lisps did. He did it deliberately because he thought static types are too inflexible and restrictive. Not just to try to appeal to Common Lisp programmers. The target for Clojure has always been Java programmers, not Lisp programmers.)

Backlinks (1 items)