Tuesday 22 November 2011

Functional Programming in Haskell

Wow, I have submitted my assignment for the Functional Programming in Haskell course.

I am really tired.

The period allotted to the assignment is six weeks. I have put in over 60 hours and taken two days leave. Yeah, I know, they said about 25 hours should do it, but it takes as long as it takes.

I have known that Functional Programming was the missing element of my experience for a long while. I asked for and was given this course by work - yay work! It is an expensive course and I could not have afforded the 7 days holiday it would have taken without their support.

These seven weeks started much earlier: This year I have written some R code, which is a sorta functional language. I tried to do some prestudy: I bought the course book and read chapter 1 twice (once on holiday). I read through the prestudy material. Very little of this cohered, but it was just enough to enable me to keep my balance during the course.

The course was great! The lecturer served on the Haskell committee. The SoftEng department at Oxford is smart in every sense. The lunches at Kellogg College were great. The other students were really bright. I just about kept up, contributing more than most and not being wrong as often as some. On Thursday I caught myself gurning during the lecture: it was all so elegant!

Immediately the course ended, I had hopes of Friday afternoon but it was not until the evening, I started organising myself. Reading the questions repeatedly, I tried chipping away at them.

Things soon went pretty horribly wrong: I could not be sure I understood the meaning of the questions, what level of completeness was expected or what shape the answers were meant to have. The assignment centred upon producers, which we had hardly touched upon and which did not feature in the course documents, consumers being the main focus. So I continued to erect a structure of yak hair: we would need a test harness, Latex processing, bibliography.

I did manage to get an answer, thought it was right, was elated. Read in Bird that my answer was wrong (though, infuriatingly the answer was 'left as an exercise'), was pretty disconsolate. Researched further and discovered that the answer was that the number of trees that can be generated from n leaves is the Catalan number for n-1.

Managed to write the generator and tests. Yay!

In between the ups and downs I had managed to pick off list, length etc.

Managed to do some pretty solid work around higher order functions, though was running out of time. I managed to finish Part I, but now only had a week for Part II and Part III.

Part II did fall out pretty easily, but it was still probably 12 hours. The tests were in place when I started to embellish with nice-to-haves, which helped.

Part II

If all tests pass then the page is written to the file system.
output :: IO ()
output = do
writeFile "fpr.xhtml" (charSequToString (showXHTMLPage testPage))
The resulting xhtml  file can be seen at [output] and is shown valid at [W3C Validator].

Part III (the essay - mine ended up as something like Discuss the Influence of FP on Java) got significantly squeezed, as I kept returning to polish Part II.

At 11.30pm I spotted a mistake in Part I - in the length function and its test.

Submitted the thing at 12.40am. Have printed it out but resisted the temptation to read it. Am feeling like a zombie.

After the deadline had passed I added a missing line break to the output, just to show that this is for me, not just for the marker.

Monday 7 November 2011

Specify InnoDb as default table type in JDBC

One of the recurrent gotchas with MySQL is that the default table type is MyISAM, whereas you almost definitely need InnoDB, if you want transactions, indexing or anything else that would make MySQL a useful database.

Set default table type for all databases

In /etc/mysql/my.cnf add: [mysqld]
But this requires that you have root access to the server and that you want all tables to use InnoDB.

Specify default on JDBC url

database.url=jdbc\:mysql\://localhost\:3306/chassis_studies?autoReconnect=true&sessionVariables=storage_engine=InnoDB You could of course use a real database!