PI3 (Haskell) at University of Bremen

So, it happened, today i passed the final test of the functional programming class here at University of Bremen. We learned about the fundamentals of functional programming and why it matters, the language of “choice” was Haskell. This post is some kind of information for students who are about to select this module and are wondering how deep they have to dive to pass it.

First things first: Just like PI1+2 it’s rather easy, you don’t have to know everything you learned in the lectures, after passing the exercises throughout the semester you just have to solve a simple, intermediate or hard programming task. Usually you’ve got a list of former exercises (in simpler form, so YOUR exam will be one of the examples plus either some minor modification or some stuff on top of it.). If you’re up for a module-wide exam you’ll have to learn some theoretical stuff about functional programming in general as well as Haskell-specific things, too (That means you didn’t pass the weekly tests over the semester) – So in case you’re wondering whether to learn those things: You should (for your own sake!), but you don’t need to. I took the intermediate task and i had to write a function similar to “indexesOf” – so the signature was indexesOf :: Int -> [Int] -> Int, not even Polymorphismic. That’s the thing you can expect when taking the intermediate task. The two guys i had the exam with chose the simple ones and had to split a list of Integers in half and invert the latter one. After finishing i was able to take a look at the hard tasks and they were really for people who are keen to have 95+% in the course. You had to deal with algebraic types and both types of Polymorphism at a higher level. They are actually doable, but it wouldn’t be enough to just write some simple code when learning for the exam. I’ll put some of the exercises I used to learn for the exam in here tomorrow, after adding a good syntax-highlighting plugin to this WordPress thingy.

At last one thing i can assure you: Functional programming is far more interesting than you might think in the beginning (If you’re coming from the OOP world or never coded before PI1 or PI2, this is some mind blowing stuff, suddenly you get things you always thought were obligatory.) and i will definitely either keep Haskell in my bag or try Elixir whenever i’m free for personal projects.

Let’s talk a bit about memory management

So after almost finishing my class on operating systems and memory management (at the easy and superficial stuff) i’ve always wondered how one can put all the theorems in a touchable context, and right after i went into the bathtub it hit me.

I’m not talking about memory management methods right now, just if you have no idea about it, think of all the methods you COULD use to fill an array or slice (talking golang now) with other arrays or slices.

The thought is rather easy, let’s say you have an empty slice with len(s) = 32 and you need to fill it with an amount of other slices that are filled with whatever, some random data. The first iteration of data would be pretty straight forward, just putting them at the first free position (concerning it doesn’t exceed the length of the array, in this case 32) – otherwise it should either be rejected or enqueued. Now the fun part begins when you delete random slices from within the slices (e.g., s[0..7] and s[11..14]) and then try to put new data in there.

Now if you’ve got two slices enqeued with len(q[0]) = 4 and len(q[1]) = 8. In case you just put the data in the first fitting (Hint: That’s a keyword) place, there’s no more room for q[1].

This is easily adaptable without even having to get on a lower level of memory management on the OS abstraction level. You can play with this idea – if you’ve got sample implementations of this “problem” (I wouldn’t call it problems, but make of it whatever you want), hit me up so i can link them here 🙂

UPDATE: I did some untested stuff in a go playground, you can play with it. https://play.golang.org/p/ei5QgXBh_7S