Teaching programming language concepts with F#

Remember when I told you about the idea of listening to recordings as taking a walk with my 3-month-old son? Today I watched the other two video recordings about F# (aka fsharp) on the Channel 9 website which I doubt I’d have found spare time otherwise.

I’m slightly interested in F# – it caught my attention just because it’s a functional programming language that borrows a lot from OCaml, SML and few others which I was told Clojure was heavily influenced by, too.

I don’t mean to learn another language – I’ve got a few to learn already with Clojure as the language of the resolutions for 2012 – but since it’s functional and quite modern it’s so akin to Clojure. My take was to completely disregard the differences between Clojure’s and F#’s syntax to solely grasp the general understanding of functional programming underpinnings.

And I do regret no minute spent on the two recordings. Really. There’re a few sentences that made me look at them quite contrary to my first reaction. Some of them are so simple that I still can’t understand why I’m so crazy about them, but it’s not the first time when a sentence made a huge difference in my understanding of topics I couldn’t get my head around before. Just a single sentence said at the right moment and I’m completely overwhelmed by its power. Shall I say enlightened?

They’re not the first and likely the last recordings which I was pointed out as potentially interesting and had almost no Java within. When I glanced at the content they firstly seemed uninteresting yet the weather outside (it’s winter and when freezing there’s not much time to have a walk) made me curious about them. They’re only 40 minutes (the first one) and 20 minutes (the other one) so they’re appropriate for a very short walk.

And so I watched.

And so I took notes when my attention was caught (when it’s white all around and nobody’s out there, it’s so easy to hear your thoughts, calm down and pay attention to details – I’m lovin’ it! :]).

In the first recording prof. Sestoft mentioned at 14:25:

“Fsharp is a functional language where most effects are achieved by computing values not by changing variables.”

That’s when I finally realized that Java (and the state mutating languages) keeps on using classes as a kind of containers you can store your data in (as a state) whereas Clojure, Fsharp and other functional languages operate on values given in a function call. No state available make you think about the data you’ve already got not the one you may collect over time (as state). It reminds me how stateless computations work in Java EE 6 where you only manipulate request data (and now Java object-orientation appears as unnecessary layer with structures that are supposed to hide data – encapsulation – but which rarely do it properly – the many getters that expose internals and hence a need for design patterns to overcome some deficiencies in our understanding of proper object-orientation).

At around 33rd minute I saw the tree which reminded me about graph algorithms to traverse trees – inorder, preorder and postorder tree traversals. Depending on the approach – with preorder tree traversal you’ll get Clojure’s prefix notation while for Java you’d have to use a mixture of preorder and inorder traversals. As I was reminded, Java has options and they used to complicate understanding. In Java, for math operations, like plus (+), minus (-) and such, you use inorder-like, infix notation, but methods change it to prefix notation.

Clojure makes life a bit easier with being consistent for its prefix notation. The first comes a function with arguments afterwards (I don’t want to bring homoiconicity to the table now).

There were quite a few sentences that made me listen more carefully, but I don’t want to spoil it with my attempts above. As an added bonus you’ll learn how pattern matching is achieved in Fsharp and the differences between FP and OOP languages. Worthy recordings.

Be Sociable, Share!
This entry was posted in Languages.

2 Responses to Teaching programming language concepts with F#

  1. kolezka says:

    I belive you meant “Learning programming …”

  2. Jacek Laskowski says:

    You mean the title should be changed? Well, it could, but it’s the title of the recordings and hence it’s the exact copy which doesn’t necessarily correspond to the content of this blog entry. A bit convoluted, but I believe it does make sense now, doesn’t it?

Leave a Reply

%d bloggers like this: