More Coursera courses

In the recent months I participated in more online courses on Coursera. Once again it’s time to share some impressions. If you care only about functional programming I suggest you skip directly to Programming Languages section of this post, but I highly encourage to read reviews of two other courses as well.

Think Again: How to Reason and Argue

Some time ago I?ve been quite interested in proper ways of arguing and in spotting logical errors in argumentations. Needles to say when this course was announced I enrolled without hesitation. It looks that this subject draws a lot of interest since this was in fact one of the most popular Coursera courses to date. The course lasted 12 weeks, which in my opinion is very long for an online course ? even Compilers took only 10 weeks. The course wasn?t very time-demanding, taking about 2-3 hours a week to watch the lectures and possibly another hour to complete the homework. I didn?t get the textbook so I did no additional reading but I guess this would take another 3-4 hours a week.

The course was divided into 4 units. Unit 1 was about analysing arguments: identifying premises and conclusions, separating relevant argumentation from verbiage, distinguishing between valid and invalid arguments, rephrasing the arguments and so on. I’m good at pure sciences and not really good at humanities so this unit was a bit hard for me. Still it was interesting. Unit 2 made a turn towards propositional and categorical logic. This on the other hand was easy for me, but I felt this was only dry theory and there was no demonstration how to apply it in analysing or giving arguments. Unit 3 covered inductive arguments, causal reasoning and probabilities. Once again the material was easy for me and interesting, but it wasn’t placed in a larger context and few applications were demonstrated. Finally Unit 4 focused on logical fallacies and refuting arguments, which are the topics I’ve been waiting for the most. The presentation of material was very good and I had the feeling I understand all of it, but when it came to tests it turned out that I actually have problems with applying in practice what I have learned. This was a bit frustrating. Oh well, I guess I wasn’t born for the humanities.

Think Again was the most fun online course I have participated in so far. This is mostly thanks to the great lecturers Walter Sinnott-Armstrong and Ram Neta, who put a lot of work and energy into lectures to make them both interesting (even entertaining) and informative. I think few things could be improved in this course. When it is redone in late August (that?s the current plan) I highly recommend it to anyone

Heterogeneous Parallel Programming

The subject of Heterogenous Parallel Programming was parallel programming in CUDA. This is a subject I got interested in recently so I decided to participate. While Think Again was one of the best online courses I took, this one is by far the worst. It’s hard for me to explain how big disappointment this course turned out to be, though perhaps I shouldn’t be so harsh on it because I decided to quit during the third week.

Heterogenous Parallel Programming was supposed to start in early September. It was delayed by almost 3 months and began at the end of November but even then it was clear that the course is not yet prepared. There were numerous technical issues with the online platform used for homework submission though this can be forgiven. What I find unacceptable however is the delayed delivery of the course material. The delays resulted in extending the course from initially planned six weeks to eight weeks, which some people on the forums have complained about and I totally agree with them. I know that it’s hard to take many online courses when they overlap and extending the course by two weeks might be a real issue. I also found the level of material covered in lectures to be unsatisfying. The course assumed knowledge of C. Still, lectures focused mostly on discussing very basic C language constructs and algorithms, e.g. during first week one lecture gave a lengthy explanation of converting index of a two-dimensional array into a linear index. Come on, this is basic C! If it was assumed that participants know C why go into details of such a basic algorithm? This was in fact the problem with many lectures I’ve watched. The pace was slow and the focus was put on C instead of CUDA. Sadly, all the lectures ended with the information that in order to learn more I need to read the book. Perhaps unsurprisingly the book is authored by professor Wen-mei Hwu, who is also lecturing in HPP course. This was really disappointing and I decided to drop out of the course when I realized that I would learn a lot more about CUDA if I spent three hours a week reading the documentation and tutorials instead of participating in this course. There were lots of other minor annoyances: course staff decided not to use the standard Coursera interface and instead created their own, which often had mistakes and broken links. While most courses send 1-2 emails a week, the staff  of HPP kept spamming the participants with tens of irrelevant emails a week (up to four a day), notifying people that “we just enabled some option” and two hours later “we changed some layout” and so on. Luckily the notifications can be turned off, but this also means you won’t get the relevant ones.

So is there anything good to be said about HPP? Luckily, yes. Professor Wen-mei Hwu was very responsive and replied to many objections people have raised in the discussion forums. As you see from the above review I am not convinced by these explanations, still it’s a big plus that he took part in the discussion. I don’t know how this course has ended. I guess that you can learn CUDA from it if you really want but judging by the first weeks of the course it’s better to just grab some online tutorials.

Programming Languages

Programming Languages is a currently ongoing course that covers different aspects and features known from various programming languages. The topics include recursion, scoping, higher-order functions, pattern matching, algebraic data types, parametric polymorphism, currying, type inference, laziness, memoization, macros, inheritance, mixins and many more. As you may have noticed most of these features are typical to functional languages and indeed the courses focuses on functional approach to programming. Languages used in the course are SML, Racket and Ruby, though the course is not about these languages per se – they are only used to demonstrate various features a programming language can have.

The course is very demanding. During 10 weeks there will be eight sections of the material. Each section has usually over 3 hours of lectures. It takes about 4-5 hours to watch them due to the breaks you will likely take between the lectures as well as the time needed to test on your own the demonstrated code. Homework is also time-consuming. It took me about 3,5 hours to complete the first assignment and 2 hours to do the peer review of other participants’ solutions (that’s part of the grading). I think this is quite a lot given my background in functional programming. Others have reported times of up to 12 hours and I know many people have given up on the course because of the difficulty. I myself have given up not because of the difficulty itself but simply due to the lack of time. Sure, learning more about SML and Racket would be fine but I’d rather spend those 8-12 hours a week working on Haskell. I still watch some of the lectures that cover topics that interest me.

While I think that making the course material challenging as it is now is a good thing I don’t like the strict policies about deadlines. There are about 9-10 days for each assignment and the hard deadline comes only two days after the soft one. Given that the lectures are released in the middle of the week, people working full-time will have to put a lot of work to successfully complete this course. That’s a pity, because the course is awesome and relaxing the deadlines would make it accessible to a wider audience without lowering the quality of material. Still this is a highly recommended course.

Don’t panic! It’s only an upgrade

Time for another upgrade of my GHC installation. OK, I know I already posted about this twice but yet again the process was different from the previous ones.

My first attempts of installing GHC and the Haskell Platform a year ago relied on using packages from my distribution’s repository. This quickly turned out to be problematic so I decided for a direct installation of the Haskell Platform. This worked perfectly fine except for the fact that Haskell packages were installed in different subdirectories of /usr/local, which lead to a bit of a mess and problems with controlling what is installed where (this is useful if you want to remove a package). So the second time I was installing Haskell Platform I was smarter and refined the whole process. This time I confined the installation to a single directory so that both GHC and all the packages are located in a single, easy to find place.

Yesterday I figured out it would be great to get a new version of GHC. GHC 7.6.1 was released on 6th September 2012 and the updated 7.6.2 version is only two weeks old. While GHC 7.6.1 has been out for over 5 months it is still not part of the Haskell Platform and it won’t be for the next three months. That’s too long a wait for me so I decided to send the Platform to /dev/null and just install GHC and its environment from scratch.

My plan to install GHC from precompiled binaries went up the spout:

This build requires

Watwatwat? Now what is that supposed to mean? Previously released binaries didn’t depend on one particular version of libgmp library. Of course my system has and any attempt to install an older version results in breaking package dependencies. I downloaded binaries anyway and tried to run them:

[killy@xerxes : ~/ghc-7.6.2/ghc/stage2/build/tmp] ./ghc-stage2 --interactive
 ./ghc-stage2: error while loading shared libraries: cannot open shared object file: No such file or directory

OK, so that requirement is true – you need the exact version of libgmp. So what now? I know! Compilation from sources! I’ve been hacking on GHC recently so I already have sources on my drive. Unfortunately it turned out that after switching GHC repo and all its subrepos to ghc-7.6 branch I get some compilation errors. I wasn’t in the mood for debugging this so I switched everything back to master and downloaded the source snapshot. From now on things are easy, assuming that you already have an older version of GHC on your system. After extracting the sources I copied $(TOP)/mk/ to $(TOP)/mk/ ($(TOP) refers to directory containing GHC sources) and uncommented the line BuildFlavour = perf-llvm. This gives me fully optimized build using LLVM. Now the compilation:

perl boot
./configure --prefix=/usr/local/ghc-7.6.2

This will build GHC and prepare it for installation in /usr/local/ghc-7.6.2. Fully optimized build takes much over an hour on all 4 cores. After the build is done all one needs to do is run make install as root. At this stage old GHC can be removed. You of course need to add /usr/local/ghc-7.6.2/bin to PATH environmental variable. As I already have mentioned I have the habit of installing all the packages system-wide in a single directory. For that I need to edit /root/.cabal/config file by adding the following entry:

install-dirs global

All that is left now is installing cabal-install. Grab the sources from hackage, extract them and run (as root) sh --global in the source directory. This installs cabal-install with its dependencies. Now you can start installing other packages that you need (a.k.a. compile the World).

This completes Yet Another Installation of GHC.

To Mock a Mockingbird or: How I learned to stop worrying and learned combinatory logic

mockingbirdYesterday I finished reading one of the most remarkable books I read in my life: “To Mock a Mockingbird and Other Logic Puzzles: Including an Amazing Adventure in Combinatory Logic” by Raymond Smullyan. When I finished reading The Little Schemer that book was listed as one of the suggested further readings. The title was quite intriguing so I got the book and started reading it. That was a year ago and I finished the book yesterday. Why? Because I got stuck and couldn’t understand some of the material. Luckily I now had some time to approach the book once again and grok it.

As the title suggests the book is a collection of logic puzzles. Out of six parts of the book – 25 chapters total – two are devoted to general logic puzzles, many of them about different aspects of truth telling. These can be regarded as a warm-up because in the third part the book makes a sudden turn towards combinatory logic. And this is the moment I found difficult in the book. Of course Smullyan doesn’t expect that readers work with combinators so he camouflages them as singing birds. Having some mathematical background I rejected this cover and tried to approach problems formally. Now, after reading the book, I think this was a major mistake that lead to my failure. I wasn’t able to deal with first 10 puzzles but I was more or less able to follow the solutions. Still I felt that reading solutions without being able to solve puzzles by myself was cheating so I gave up. A few months later I made another approach to the book but the results were exactly the same. Three weeks ago I made a third attempt, but I decided not to give up even if I won’t be able to come up with my own solutions. I figured that being able to only understand given solutions is completely fine. That decision turned out to be a good one. Although at first I wasn’t able to solve puzzles on my own at some point things just clicked. I solved one puzzle, then another and another and I realized that I know how to solve most of the puzzles. From now on the book went quite smoothly. Part four about logical paradoxes and inconsistencies in logical systems gave me some problems and I was afraid that each subsequent part will be equally challenging but it turned out that it was not the case. Part five gives a nice overview of computations using SKI combinators, while part six presents Church encoding of natural numbers and culminates with a proof of Gödel’s theorem.

Some advice

The book is challenging on the one hand but it is also very rewarding. One of the most satisfying moments was realizing that I am able to write expressions like


and then seeing that these are in fact nothing more but recursive programs. However it took me some work to get to this point and I think I can give future readers some advice about approaching the book. I’ve seen people on the internet saying they don’t understand parts of the book about combinators. In fact this is the same problem I faced on my initial contact. So my advice number one is: don’t give up. It looks like working with combinators just isn’t an inborn talent for most of us. It’s something that we just need to learn and it’s completely fine if you can’t figure out solutions on your own. It is important however to follow solutions given in the book. At some point you should understand how all of this works. Also don’t make my mistake of trying too formalize things to much. Don’t try to apply presented facts about combinators to anything else you know like maths or functional programming. This seems to only bring confusion. At some point things will become clear, but until then be patient. I wasn’t and in my attempts I even tried to introduce universal and existential quantification, which was a complete overkill. Also, it is very important to make notes. Keep conclusions of the puzzles in a notebook so you have easy access to a list of known facts. This is crucial since some solutions are based on facts proved 100 pages earlier. I also suggest having a separate scratch-pad.


To “Mock a Mockingbrd” was a very insightful book and one of the most unusual ones I have read. It presents difficult material in a fun and entertaining way, but don’t be fooled – you will spend hours with pen and paper to complete this book. I highly recommend it to anyone interested in logic and functional programming. What functional programming has to do with it? Unrelated as it may seem I feel that this book has given me knowledge necessary to tackle type-level programming in Haskell. Just three weeks ago this seemed like a complete black magic and now it looks comprehensible.

Staypressed theme by Themocracy