Picking a functional language

work safe

Somehow, I’ve been suckered and bamboozled. I’ve been talked in to prepping an internal course on Functional Programming. To talk about functional programming, I need to have the students actually program functionally. There are several choices I’m considering; FSharp, Clojure, Haskell, and Erlang. There are plenty of others, but I’m not as familiar with them so they won’t be considered. They each have their own strengths and weakness.

Clojure was started on top of the JVM (Java Virtual Machine), but is also being ported to the CLR (Common Language Runtime). It’s a dynamic functional language that is a part of the Lisp family of languages. There’s a lot to be said for it. It’s got Macros. It’s got all kinds of documentation. It’s got all kinds of libraries. It has great IDE support. It even has a bunch of Emacs support as well.

Haskell is a research language that’s crossed in to industry. It compiles to machine code. It is strongly typed, way stronger typed than Csharp or Java. It is type inferred. It is Lazy and Pure. There is a community of developers releasing libraries. There are some really good documents as well. Many interesting functional research papers use Haskell as their implementation language.

Erlang is an industry secret that escaped to main stream use. It is a dynamic language that runs on it’s own interpreter. It has a bit parsing syntax. It has strong networking support. There is a growing community and some good documentation. It has a phenomenal set of libraries for concurrent programming.

FSharp is a fairly new language from Microsoft. It’s a strongly typed and type inferred language. It has some great language extension features like workflows and quoted code. It is a variant of Ocaml. It lives on the CLR and integrates well as a consumer of .NET libraries or as a .NET library to be consumed by C# code.

They are all very different and have different focuses, so I had to eliminate some. Erlang is out because it is almost too focused on concurrency to the point of distraction. Haskell is a wonderful language but has a sovereign ecosystem that would preclude it from being used with the majority of our work. Clojure is wonderful and I can turn a bunch of existing material from Scheme or Lisp without much work, but it is mainly a JVM language and I can’t vouch for the completeness of the CLR implementation at this time.

This leaves FSharp as my language of choice. It plays well with .NET and we have a LOT of .NET projects. I can use a lot of Haskell resources as a starting point. It should work well. I’m looking forward to class.



  1. RPH  •  Mar 22, 2011 @8:28 am

    Out of curiosity, what about Scheme or Lisp? You already mentioned you have a bunch of existing material in those languages. In my opinion, the important part of functional programming is the concepts, and once you’ve learned those you can bring them to you language of choice. We have a lot of functional-esque code in our C# code base, for instance.

  2. Matt A  •  Mar 22, 2011 @10:25 am

    Interesting timing – I saw this week that Carnegie Mellon has added FP to their freshman curriculum, along with imperative programming. They’re relegating OO to an optional sophmore level class.

    I would like to offer Javascript for your FP consideration. Benefits: The devs have seen it, might even feel comfortable with it, and will likely use it directly. Though a drawback is that they may feel comfortable with it and work around your lessons.

    I think your reasoning for picking F# sounds good, though I would also like to echo (my interpretation of) Rob Patrick Harris’s sentiments. Namely that you could start with Clojure to develop the skills, then have a couple lessons at the end that implement that stuff back using C#. It would be especially interesting to show “the structured way” vs “the FP way”. I’d think that C# (and Javascript) are much more likely to be used than F#, so might as well go there directly at some point.

  3. Ball  •  Mar 22, 2011 @10:58 am

    These are good points.

    Why not scheme or lisp? Because I like Clojure better, even though we actually have billable Scheme work, because it plays well with others and isn’t isolated like Haskell.

    Why not JavaScript? because there is a bit too much ceremony in the language and I hate the DOM but haven’t looked at NodeJs.

    The other thinking with FSharp is I can transition to and from C#. I have in my mind starting with pure FP concepts for a while then introducing FSharp’s OOP. Then using C# to explain the concepts we’ve been building up.

    I think it is important to see and understand FP as first class before speaking the pidgin of FP that C# has.

Leave a Reply

Allowed tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>