Category Archives: Computers


R.I.P. Steve Jobs

(Though probably not M.I.X. Or B.U.R.N.)

Steve Jobs has died, and the media and the… Blogosphere? Social Nethood? …is showing an outpouring of, well, grief is the wrong word, but praise and love. Maybe grief is accurate, actually.

Not the kind of grief you have for your grandparents dying, but perhaps the kind of grief for a friend of a friend.
Continue reading

iCal woes

It is an article of faith amongst Mac users that their system of choice is inherently superior to (spit) Windows. Not only that, but it never crashes, loses data or does flaky, unpredictable things.

I’m here to tell you that they are deluded. Apple software generally is not bad, but it’s not infallible. In particular iCal and Address Book have over the years caused me endless hassle and pain.

Anyway, this post is an aide-memoire for me, if nothing else, about how to fix infuriating iCal issues.


Firstly download and install the brilliant iCal Dup Deleter. Various iCal issues, including duplicate entries, missing entries, the appearance of things which you thought had been deleted, and general flakiness, can be solved by running this tool on each of your calendars.

Download it here:

I’ve even seen my calendars go completely blank—all the entries disappear—and that’s a bit frightening the first time you see it, if you depend on iCal to keep track of your appointments—and it can often be fixed quickly and easily by iCal Dup Deleter. Loverly.

Restoring from backup

On recent versions of OS X, calendars are stored in “~/Library/Calendars” (not in “~/Library/Application Support/iCal”, though if you’ve upgraded through several versions, that directory may still exist).

In addition, the program preferences are stored in “~/Library/Preferences/*” You can safely delete the preference files. Sometimes that flushes out problems.

Hang on startup (iCal and AddressBook)

Had an issue today whereby I lost all my events, but iCal Dup Deleter didn’t work either.

Tried restoring the directory from backup, and that failed: iCal would hang on startup. I had a nightmare attempting to restore individual calendars, deleting lock files; nothing worked.

Turned out to be a problem with AddressBook(!). AddressBook hung on startup and (I’m hypothesising), iCal hung waiting for AddressBook. Deleted the various lock files:

cd ~/Library/Application\ Support/AddressBook
rm .database.lock
rm .skIndex.ABPerson.lockN
rm .nfs.20051025.00d1
rm .AddressBook-v22*

…and AddressBook started normally and so did iCal. Hurrah!

Prince: brilliant musician; funked-up brain

In other news, Prince is apparently actually my grandmother:

“They [computers and digital media] just fill your head with numbers and that can’t be good for you.”

His new album is available only on CD, and not iTunes, Amazon, eBay… and he’s closing (closed) down his own website (presumably because he doesn’t want to fill other people’s heads with numbers and thus contribute to the problem). So he’s promoting it on MTV? Ah, probably not, since MTV is ‘outdated’ the same way the Internets are.

So expect his ship-to-ship–semaphore–(or possibly telegram)–based marketing campaign to commence in 3… 2… 1…

(Good thing noone’s told him that CDs are digital.)

Incidentally, his cover of Radiohead’s Creep is brilliant.

Hindley-Milner type inference in Scala

I’m working on a spreadsheet application at the moment. (Very exciting.) Part of the implementation obviously includes an expression language (so you can write things like total = sum(numbers) or vat = price × 17.5%).

Part of the design is to disallow things like "text" ÷ 11 or apples + oranges, and for that I need a type system.

So I’m investigating type systems, and rules for inferring types, and I’m looking at the algorithm they call Hindley-Milner type inference. I found an implementation of the algorithm in Perl by Nikita Borisov. This was in turn based on a Modula-2 implementation described in a paper by Luca Cardelli, Basic Polymorphic Typechecking (1987/’88). Given that I read maths only very painfully and slowly, it’s a very clear and readable paper.

I have reimplemented the algorithm in Scala (the language I’m using for my application).

Because Scala is itself a statically-typed language, some of the logic becomes clearer than the Perl version (for example, it is obvious where type variables are expected as opposed to type terms). Scala is also somewhat syntactically lighter than Perl, and a lot lighter and more expressive than Modula-2, so you may find it easier to read too.

The essential algorithm is elegant: given an expression in the form of an abstract syntax tree (AST), it recursively creates a tree of types in the expression, inserting placeholder ‘type variables’ for all the unknowns. It then ‘unifies’ sub-types, for example, ensuring that a function call’s result type is the same as the function definition’s result type. The final unification creates the most general type tree possible which accurately captures the expression type. The final unification may include still-unbound type variables, which would indicate that the expression is polymorphic in these type variables.

My code is available for download in the hope that others find it as useful as I found Luca Cardelli’s paper and Nikita Borisov’s Perl implementation:

You can run it as a script to see it analyse some example expressions: scala HindleyMilner.scala

Note: I believe that there was a mistake in the original Perl code; when unifying two variables, it tried to ensure that generic type variables were always bound to non-generic ones, not the other way about. This was in order to satisfy the requirement “In unifying a non-generic variable to a term, all the type variables contained in that term become non-generic.” However, it does not matter the order in which they are bound. Once the ‘bindee’ is further bound to a term, they both become bound to the same term. The original code omitted a call to prune in the method occursintype which (I believe) lead to a fault, for which the mistaken ‘fix’ was added.

Update 15 Sep 2013: Now compatible with Scala 2.10!