Archive for the ‘beauty’ Category

More from the list monad

Wednesday, July 18th, 2007
Prelude Control.Monad> let truthPermutations n = replicateM n [False,True]
Prelude Control.Monad> truthPermutations 3
[[False,False,False],[False,False,True],[False,True,False],[False,True,True],
[True,False,False],[True,False,True],[True,True,False],[True,True,True]]
Prelude Control.Monad> let satisfies p [x,y,z] = p x y == z
Prelude Control.Monad> filter (satisfies (==>)) $ truthPermutations 3
[[False,False,True],[False,True,True],[True,False,False],[True,True,True]]

Try expressing truth tables so succinctly and at such a high level in an imperative language. The list monad rocks.

One-line definition of the power set function

Monday, July 2nd, 2007

If you thought the one-line definition of the Fibonacci sequence in Haskell was beautiful, try this:


import Control.Monad
powerset :: [a] -> [[a]]
powerset = filterM (const [True, False])

A black box for sure, unless you have “internalized the list monad“. But it does show how stonkingly powerful monads are.

Abstract category theory is like…

Sunday, June 24th, 2007

writing without nouns.

But ahhh, to write nounlessly is to live anew, not to be tied to thinking concretely, not to be anchored, not to be grounded, but rather to lift off and fly, as if previously to write was just to crawl, penned in, hemmed in, restricted.

And I might add, like an Oasis song, to say everything and yet say nothing. (The traditional way to express this is to call it “abstract nonsense“; the book Abstract and Concrete Categories: The Joy of Cats has this cute limerick which captures the feeling:

There’s a tiresome young man from Bay Shore.
When his fiancĂ©e said, “I adore
The beautiful sea,”
He said, “I agree,
It’s pretty, but what is it for?”)

Journal time: I came back from a week back home in Hampshire today, after going with my brother to the Muse concert at Wembley on Sunday. (Woo! That was brilliant!) We also went to a Spanish restaurant for Dad’s birthday, which was pretty tasty.

Our degree results came out yesterday, but I wasn’t around to get them, so I’m having to hold my breath until Monday.

Type inference rocks

Monday, May 28th, 2007

I just wrote the following snippet of code for my dissertation:


intNatI :: Int :~= Nat
intNatI = Iso {
            to   = fromInteger . toInteger,
            from = fromInteger . toInteger }

The components to and from have totally different types (to is Int -> Nat, from is Nat -> Int). Yay for type inference! :)

Any fool can be a wizard

Wednesday, September 20th, 2006

Having received the shocking news that Elsmorian has never heard Tommy, I went back and listened to it again myself. While I was listening I read the Wikipedia article, which says “Townshend’s later interest in synthesizers is foreshadowed by the use of taped sounds played in reverse to give a whistling, chirping sound on ‘Amazing Journey’”. I thought “really? never noticed” and listened to it once more.

It’s funny when you revisit things you’ve listened to casually before and discover new depths. I only even noticed these funny chirpy sounds when I listened to them again just now, while they add a wonderful other-worldliness to the song, reinforcing the idea that it’s all a vision inside Tommy’s head. They sound great even today, but it was only when I realised how fantastic they must have sounded in 1969, when the album was released, that I could appreciate it properly. Bear in mind that I’ve been brought up in a musical culture where synthesisers are mundane (we call digital ones keyboards now) and sounds like that are trivial to create with the audio equivalent of the universal constructor, the waveform editor. I think it’s rather sad that my appreciation of it is jaded by having heard similar sounds hundreds of times before, as just another instrument.


It all reminded me of Terry Pratchett’s remarks about conjuring in his interview with Stephen Briggs in The Discworld Companion (my copy is the second edition), where he explains that he would probably enjoy a Discworld play, with its improvised, amateur special effects, more than a Discworld film, with big-budget CG:


I suppose I’m saying it’s the difference between magical tricks being done by a genuine wizard and by a stage conjuror. The wizard does marvellous things but it’s, well, magic and therefore in a sense mundane. Yawn yawn, he’s produced another damn pigeon, well, that’s magic for you. But when you know it’s being done by a conjuror with a hearing aid and a day job down at the building society, and all achieved by springs and elastic and secret pockets, this makes it much more interesting. Any fool can be a wizard, but you have to be clever to be a conjuror.

I think you can say the same for any look back at past innovations. It’s difficult to appreciate the cleverness of past inventors when the modern man looks at their inventions and shrugs — to him, they’re just a prosaic part of his world, no more amazing than a flint knife would have been to a caveman.