14

I like Haskell, plain and simple. While Haskell is used in production software, it's not especially widely deployed from what I've seen. What is the most similar and still widely used language in regards to production projects so that I might have a snowball's chance of using something similarly awesome in industry?

Also is the same language from the first part available on large numbers of platforms? If not, what is the best alternative that has wide platform deployment? I'd like a single language to put on my to-do list rather than a massive swarm or family. Hard evidence would be a plus.

5 Answers 5

21

Haskell is most closely related to the ML family of languages. This includes things like OCaml, of course, but also F# on the .NET platform. These languages share with Haskell the foundation of the type system and how data is used--algebraic data types, pattern matching, type inference, etc. They can differ substantially from Haskell on other points, of course--most MLs are strict and impure, to start with, and the popularity of Haskell as a vehicle for research in type systems and language design means that most ML-style languages tend to have less powerful (but potentially easier to understand) type systems. It's probably safe to say that while you may miss some things about Haskell, particularly at first, most Haskell programmers would probably feel comfortably at home in an ML pretty quickly, at a basic getting-things-done level. If you want a language with the same overall structure as Haskell, an ML is your best bet.

The functional side of Scala draws heavily from the ML tradition, as well, and also pulls in some advanced type system features familiar from Haskell, as well as a more standard OOP system integrated with the above. While OO in ML-style languages tends to be approached as more of a "model OO with basic functional tools" Scala lives and breathes Java-style OO. This has benefits for Java interop, as you might imagine, and presents more familiar working environment for OO programmers. However, coming from a Haskell background, you're more likely to be annoyed by ways that blending things together in Scala makes functional idioms clumsier, and find most Java APIs to be badly designed and needlessly difficult to use. So if you want something with a sophisticated type system that permits direct translations of many things in Haskell (with some extra syntactic overhead) and don't mind compromising on functional style, you might enjoy Scala.

Finally, while it may seem odd to consider, Clojure actually has a lot of things in common with Haskell at a more philosophical level. Most of what you'll find in Clojure's approach to state and values vs. identities is very close in spirit to what Haskell formalizes through the type system. Correspondingly, Clojure emphasizes Java interop to a smaller degree and doesn't worry as much about dragging in OOP, so in some ways Clojure's approach to functional programming itself may be closest to what you're already familiar with. I think it's telling in this regard that, to the best of my knowledge, Clojure is the only language besides Haskell that has an implementation of STM that's simple, effective, and just works. On the other hand, Clojure comes from the Lisp tradition and thus lacks the static type system and emphasis on algebraic data types and pattern matching found in ML-influenced languages. And of course it's a Lisp, which is itself a negative to some people (though I really don't know why).

Speaking for myself, with the disclaimer that my first experience with functional programming was in Scheme, I'd probably lean toward Clojure, with OCaml a likely second choice.

1
  • 1
    F# is said to have been inspired by, if not derived from, OCaml. A previous SO question, F# and OCaml, covers a good discussion of that relationship. If you are on the .NET side, F# would be an excellent choice and Microsoft now considers F# a "first class" .NET language. On the JVM side, Scala has a track record of industrial use and Clojure seems to be rising in the charts. I do not know of any single best choice, at this time, as the marketplace has not yet declared a clear winner in this object-functional space. Sep 1, 2011 at 16:47
4

I never used it myself, but I see Scala popping up in blogs or project descriptions sometimes and I believe it took major concepts from Haskell. Scala compiles down to the JVM and can interoperate with Java.

4

A functional alternative is Erlang. While it is a very concurrent language the sequential subset is a pure functional language with many of the properties of functional languages, for example closures, immutable data and pattern matching. It runs on many platforms including linux, various unixes, windows and macosx. There is now even an implementation on the JVM, erjang. It can easily communicate and co-exist with other languages, this is how it is often used.

Check out the main site.

3

Clojure is increasingly widely used, and while it is does not look like Haskell at a superficial level, if you look a bit deeper it is clearly very much inspired by Haskell and encourages a very similar functional style.

Key Clojure features that Haskell users may find familiar and compelling:

  • The core language is purely functional - while side effects are possible they are buried away in specific places (e.g. STM references, IO functions, Java interoperability)
  • All data structures are immutable and persistent
  • Laziness - achieved largely through Clojure's ubiquitous lazy sequences, this will feel very familiar to Haskell users. Infinite lazy sequences are fine.
  • Software Transactional Memory - is the main way of handling mutable state in Clojure. Well worth watching this excellent video where Rich Hickey explains Clojure's approach to identity and state: http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey

Key differences (may be positive or a negative depending you your perspective):

  • It's impure - although my observation is that idiomatic Clojure style is to stick pure functions wherever possible.
  • Dynamic rather than static typing (although static type hints can be used optionally for performance optimisations)
  • It's a JVM langauage with easy access to the whole Java library ecosystem - this is in my opinion the biggest advantage in terms of real world applicability
  • Lisp syntax. So you get all the benefits of homoiconicity, at the cost of having to learn to see through all the parentheses :-)

Personal perspective: I learnt Haskell before Clojure, and loved Haskell for it's elegance and mathematical purity. Clojure draws a lot of inspiration and borrows many good features from Haskell, but is a much more pragmatic/practical langauge. Especially when you count the huge value of being able to leverage the Java library ecosystem then it's a great language for "getting stuff done".

1

If you like Haskell, but have to make code for the JVM, frege may be interesting to you. It is designed to be as close as possible to Haskell 2010, yet generates Java code.

Of course, frege itself is nothing like "widely used production language" (it's just recently published), but Java is certainly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.