From Hash Key to Haskell

2008-01-19, , , , Comments

Mac Hash

How annoying, there’s no hash key on the Mac UK keyboard!

SHIFT+3 gets you the UK pound sign, £ (I’d prefer the Euro, €), and once you’ve found that you’re in the right vicinity — as if by magic, ALT+3 produces the #.

Unfortunately this same key combination doesn’t work on the Windows XP virtual machine I run under Parallels. I’ve done enough configuring to get the Mac keyboard working tolerably with this virtualised XP, but whenever I need to enter a # I’m reduced to cutting and pasting.

Trigraph Confusion

C and C++ programmers could avoid the # by using trigraphs, an obscure language feature which allows you to write ??= instead. Yes, there are other trigraphs. Courtesy of Wikipedia, here’s an example program which uses them all.

??=include <stdio.h>

int main(void)
    char n??(5??);
    n??(4??) = '0' - (??-0 ??' 1 ??! 2);
    printf("%c??/n", n??(4??));
    return 0;

Impressively unreadable!

What you see is not what you type

An important difference between a typewriter and a text editor is the software between keypress and screen update — the software I’ve failed to fully configure on my virtual XP machine. So why not exploit this indirection?

Developers of mobile phones have grown ingenious at adapting a numeric keypad to generate text almost as ably as a QWERTY one. (Which do serious texters prefer, I wonder, an iphone or a numeric keypad?) And my instant messenger client is cute enough to display smiley punctuation sequences as emoticon graphics.

Python smiley

On which point, has anyone else noticed the square-jawed smiley you get when you chop the last element from a Python list? This one’s wearing a cap.


Readable Haskell

Haskell is one of my shiny new things for 2008. I’ve scratched at it before and one of the things which put me off is the number of digraphs in the code. They don’t look right. I’m talking about the arrows in particular:

->  <-  =>

Of course I’m used to the logical digraphs &&, || and the comparison operators, ==, <= etc. These don’t look out of place in the C family of languages, but Haskell’s roots seem closer to mathematics and logic; it craves proper mathematical and logical symbols.

Haskell Logo

The symbol Haskell uses for anonymous functions is a single backslash, \. This should of course be a lambda, λ. It’s ironic that this character is the star of the Haskell homepage but can’t be found in Haskell source code.

It shouldn’t be too hard to view and edit Haskell code using more appropriate characters even if you actually input them as usual. Oh look, Emacs does it already!

Set (setq haskell-font-lock-symbols 'unicode) and your Haskell code will look something like the sample shown in the upper screen below (I’ve split the editor window and shown a plain-text view of the same content in the lower screen).

Emacs Haskell mode screen grab

Much better!