Functional Languages and Scala

For a while now I’ve been thinking about learning a functional language (XSLT excluded). I was always fond of Haskell at university, but it seems to be an academic language without many ‘real world’ uses. The other obvious choice would be Common Lisp, but the syntax really puts me off. Another one that caught my eye is Erlang because I’m doing some distributed programming at the moment, but the only book on Amazon costs 50 quid, which dampened my interest.

Today I came across a language called Scala. Strictly speaking it isn’t a functional language, it’s a hybrid of OO and functional.

Scala is object-oriented
Scala is a pure object-oriented language in the sense that every value is an object. Types and behavior of objects are described by classes and traits. Class abstractions are extended by subclassing and a flexible mixin-based composition mechanism as a clean replacement for multiple inheritance.
Scala is functional
Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and supports currying. Scala’s case classes and its built-in support for pattern matching model algebraic types used in many functional programming languages.

But a lot of these features also exist in Ruby, another language I’ve been playing with. So why does Scala peak my interest? It runs on the JVM and can use all the existing Java class libraries. This means I could use it on my projects at work, i.e. something reasonable complex. The most I’ve pushed Ruby is to do some processing for a web site, hardly rocket science, and it’s foreign enough I couldn’t just start using it at work.

A JVM compatible language with higher order functions, mixins, operator overloading, built-in XML processing…I don’t think I’ve been this excited by a programming language for quite some time. ;)

Spread the word: Technorati related  |  Technorati related  |  del.icio.us bookmark it!  |  submit Functional Languages and Scala digg.com digg it!  |  reddit reddit!

6 Responses to “Functional Languages and Scala”

  1. JD says:

    Jython

  2. Miles says:

    I wasn’t actually aware that Python had some of these features, but what really attracts me to Scala is some of the functional language features like pattern matching, currying, tuples, etc.

  3. JD says:

    Yes, python has tuples, currying[0] and pattern matching. It also has functional functions like filter, map and reduce.

    It also has the advantage that many people can program in it and it doesn’t involve realising there is no spoon.

    [0] 2.5 with have inbuilt currying, but in the mean time you can use http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52564

  4. Simon says:

    Don’t be put off by Lisp’s syntax. I admit it does take a while to get used to — I’m still not that keen on it now — but it’s worth taking the time to learn it as it is a powerful language. I learnt quite a lot from using it as it has some features you don’t really find in more mainstream languages. This is a really good book to get you started: http://www.gigamonkeys.com/book/, and best of all, it’s free — unless you choose to buy a hard copy of course!

  5. JD says:

    Except it lacks the ability to run on a JVM, which is kind of important if you’re trying to target an existing java product.

  6. Miles says:

    I just found SISC (Second Interpreter of Scheme Code) that runs on a JVM and can call Java code, and allows Java code to call Scheme code. That doesn’t mean I’m going to go out and learn Scheme, but it remains on the todo list, so maybe one day. :)

Leave a Reply

Line and paragraph breaks automatic.
XHTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>