This sentence is false

functional programming, software, and emacs.

Next Language?

Recently I’ve been thinking, “I’ve done the Lisp thing. Also, SML and OCaml. What’s the next language I could learn that will change the way I think about programming?”

Erlang seems pretty cool. Really inexpensive parallelism and built-in capability for distributed process on a bunch of machines. Pattern matching. Built-in tuples. All good things… but it’s dynamically typed. The benefit of strong typing (every expression has a type, inferred or declared, at compile-time; and types are checked) is well known. I have taken this to heart, and programmer friends of mine know I get very testy when someone threatens my Hindley and Milner.

Haskell, on the other hand, has a magnificently expressive type system. It has dependent types, generalised algebraic data types, and type classes, all which make for a fruitful compilation step and contribute to code confidence. Type classes in particular provide operator overloading0 in a type-safe way. But if languages are schoolteachers, Haskell is a pushover: it has non-strict semantics. This property is less-accurately1, but more commonly known as laziness.

I don’t like this aspect of Haskell. It seems to make it hard to reason about the complexity of an algorithm. “Am I accumulating stack?” While it might be quick to code something correctly, coding correctly and efficiently is a less obvious process for me.

Ignoring these options, however: who’s to say I’ve really understood Lisp, SML, or OCaml? Some would have it that it takes longer than a few years to really become an expert in any reasonably general-purpose language. I like this, and so my current plan is to stick it out for a while with OCaml (education permitting).

Currently I’m exercising my OCaml-fu by implementing a parallel Sudoku solver in Jocaml. Jocaml is an extension of OCaml that implements the join calculus, a formal language for asynchronous communicating processes. Basically, instead of just wrapping some system threads library, Jocaml provides orthogonal primitives to describe fundamental building-blocks of processes and how they communicate. As a bonus, the whole thing is formal, so you could conceivably prove theorems about a program written in Jocaml, because there is a mathematical theory underlying all the asynchronous bits.

[0]Also called ad-hoc polymorphism, though I’ve yet to discover why.

[1]In my vocabulary, strict semantics is a language property meaning that evaluating an expression involves first completely evaluating its subexpressions. It follows, then, that a language has non-strict semantics when it does not have strict semantics.

One consequence of non-strict semantics is the possibility of embedding non-terminating expressions in a terminating program. For example, suppose use-first-argument is a binary function that does exactly what it says, namely does something with its first argument only, ignoring its second. In a strict language (e.g. everything, mostly), where \perp stands for an expression whose evaluation never terminates, the function call use-first-argument (X, \perp) will never terminate. In a non-strict language (Haskell), that code fragment will return whatever use-first-argument returns. If the expression’s value is never needed, it is never computed, and hence the infinite recursion is never triggered.

To return to the point, laziness is the property of a program or data structure — a value can be lazily computed by saving intermediate results until the final result is manually requested, at which point evaluation occurs. Laziness can be written into Java, or OCaml, or any language. One example is a common pattern in OO system implementation: set the values of member variables the first time they are accessed, rather than upon initialisation of the class.

03 July 2007 - Posted by dbueno | lisp, objective caml, sml/nj | | 9 Comments

9 Comments »

  1. It seems a bit odd for you to say:

    “What’s the next language I could learn that will change the way I think about programming?”

    And then proceed to explain the faults of languages you have little or no experience with based on preconceived opinions.

    (Also, have you considered D?)

    Anyways, there’s my $0.02. Hope grad school is treating you well.

    Comment by Matt | 05 July 2007 | Reply

  2. Yes, it does. The notions are not really preconceived. They’re based on research (manuals and examples) as well as playing around with toy programs. Some of the features of Erlang are present in other languages I know (pattern-matching, higher-order functions, tuples: ML). Haskell also shares a lot of commonality with OCaml and SML (the type system), though there are obvious differences.

    The post was supposed to be a springboard to make the point that a year or a few aren’t necessarily enough to grok any language, and that I plan on “changing the way I think about programming” by simply sticking with a language I know (or extensions of it). Perhaps one day I’ll find that another language really provides the Big Hammers necessary for a particular project, at which point, I’ll use it.

    I’m also going to point some more about Haskell, to show concretely how it makes it difficult to reason about the complexity of algorithms.

    Nevertheless, you’re quite right — in essence I’m saying, “Let’s see what’s different from what I know, and learn that language! *looking around* Ew, that language is different. Send it back.”

    Comment by dbueno | 05 July 2007 | Reply

  3. re: D

    No, I haven’t. I’ll look it up.

    Comment by dbueno | 05 July 2007 | Reply

  4. I am not really convinced about D. It looks like a bastard to me.

    My suggestion is to try scala. It has a lot of really advanced features and it’s really cool.

    Comment by Christian | 05 July 2007 | Reply

  5. What about Oz (part of the Mozart system), It has a very very cool book too (http://www.amazon.com/Concepts-Techniques-Models-Computer-Programming/dp/0262220695)

    (I’m on the ML bus at the minute because I want to be able to use FP at work and microsoft’s F# seems like an easy sell)

    Comment by David | 26 July 2007 | Reply

  6. You should look at smalltalk. It’s still top of the line many years later, it will change the way you think about OO programming (and all the general kludges of programming with various languages) and you can easily do functional programming with it.

    Comment by name(required) | 28 July 2007 | Reply

  7. I have used smalltalk to implement a graph (mathematical) visualisation app. Basically it supported creating un/directed graphs and calculating things like the minimum spanning tree, shortest paths, &c.

    And I liked Smalltalk. It has a really simply language paradigm and that makes it easy to program in. Plus it has a killer set of libraries. And I did implement a few functional extensions (like real fold) in order to do that project. It was fun.

    Comment by dbueno | 01 August 2007 | Reply

  8. Jack of all trades … how does that end again?

    Comment by Curtis Jones | 13 September 2007 | Reply

  9. Strachey coined the term “ad-hoc polymorphism”
    his paper must be on the net somewhere…

    Comment by zob | 18 November 2008 | Reply


Leave a comment