Archive for August, 2008

Aug 21 2008

Lord of the Flies as a window onto monadic IO

Published by Dougal under Programming

I like thinking about monadic structures in Haskell as universes — a different universe for each one — a universe of non-determinism, a universe of mutable state, and so on.

The IO monad, by this analogy, is our universe. Whatever happens in the IO monad actually happens. It’s necessary in Haskell to enforce an ordering on actions which affect our universe, because in a lazy language you don’t have much of an explicit ordering. So functions in the IO monad are allowed to change the world, and only one can do this at a time. It’s a bit like a State monad, except nobody actually bothers passing round the entire state of the universe from one function to another because that would be silly. As far as I can tell, it’s normally an access token. Like a conch, I suppose.

Sometimes, though, you might want to play out a hypothetical situation. “I don’t have the conch right now, but if I did this is what I would say…” This tricky hypothetical universe will then vanish when you’ve finished your little daydream. The Haskell way of doing this is with unsafePerformIO. It lets you make your own conch (well, maybe just a barnacle?), which can be very useful and very dangerous. You may do things which are very useful, but you might also destabilise the state of the world, bringing chaos and so on.

I recently had cause to use it in Brent Yorgey’s Diagrams package. It’s a lovely EDSL for creating simple diagrams, which is built on the Cairo library. The one thing it didn’t support was text — the very thing I wanted to use.

Brent’s library has an interface for all the shapes you might need to draw. Each shape has to supply functionality to (a) return its own size and (b) draw itself. Part B was easy enough, since all that is basically done by Cairo library. I was just joining it in the right place. The size part was much harder, since the size of a label is dependent on the typeface, font size and the characters used. You can’t really tell ahead of time what it will be.

My first thought was to let the user add a bounding box which the text would fit in, but this is almost totally unusable in practise. The proportion of width to height changes depending on the text and the font in use (as well as the size, if you assume hinting). You’d have to be clairvoyant to know exactly the width and height required so that the text wasn’t squished sideways or flattened at awkward proportions. And I was assuming that people would want text that was readable without much effort.

My next attempt was to assume the bounding box was only the upper limit, but if the text had to be shorter in either dimension to look good then it would be. This works reasonably well for a single chunk of text, but there’s no consistency. The only way to ensure consistent sizes across multiple labels is if they all say the same text in the same font. This is just as unreasonable as the requirement that the user by clairvoyant.

My problem — the real problem that was demanding all these awkward workarounds — was that the shapeSize function was pure and textExtents was decidedly not.

class ShapeClass s where
  shapeSize   :: s -> (Double,Double)
  renderShape :: s -> DiaRenderM ()
 
textExtents :: String -> Render TextExtents
fontExtents :: Render FontExtents

In fact, the monad Render is a huge stack of monad transformers

newtype Render m = Render 
        {runRender :: Control.Monad.Reader.ReaderT Cairo IO m}

The two are not even slightly compatible in most situations.

In the end I bit the bullet, and used unsafePerformIO. I am pretty sure that it doesn’t affect the world. In effect, I am saying to the Cairo library:

“if I were to give you this string BLAH, what would you say the bounding box would be around it?”

“Oh, I’d say about X and Y. Why do you ask?”

“Oh, no reason…”

I think I’m safe.

2 responses so far

Aug 19 2008

If you don’t have anything nice to say, say it on lawyer’s headed paper

Published by Dougal under Bad Science, Health

Clearly the chiropracters need to take a good long look at their PR strategy. Two separate incidents from opposite sides of the world within a few months of each other — and both incredibly stupid.

CCC: Cat Chiropractic Clinic
CCC: Cat Chiropractic Clinic
© Kevin

In the New Zealand Medical Journal David Colquhoun wrote about Inappropriate use of medical titles by some “alternative” medicine practitioners. Rather than keep quiet about this editorial and hope it would blow over, the New Zealand Chiropracters’ Association sent a letter from their lawyer, demanding retraction and apologies. The journal printed the legal demands in full, with a statement from the editor:

The Journal has a responsibility to deal with all issues and not to steer clear of those issues that are difficult or contentious or carry legal threats. Let the debate continue in the evidence-based tone set by Colquhoun and others. … I encourage, as we have done previously, the chiropractors and others to join in, let’s hear your evidence not your legal muscle.

Now it should be very obvious that the New Zealand chiropracters would rather resort to a legally enforced muzzle than demonstrate the efficacy of their treatments. One can only hope that this kind of embarrassing repercussion will be enough to make them think twice about legal threats in future.

Something very similar has been going on much closer to home, and it’s the chiropracters involved again. Simon Singh wrote an opinion piece for the Guardian way back in April, for Chiropractic Awareness Week. True to form, the British Chiropractic Association is suing for libel. The original article has been pulled from the Guardian website, but has been quickly replicated elsewhere.

The best reposting is on Gimpy’s blog: the article comes with full references for every one of Simon Singh’s assertions.

It should be pretty obvious now that these two associations have little interest in medical science or patient wellbeing. If they did then stifling criticism would not be their first reaction.

9 responses so far

Aug 18 2008

Airy ciabatta, drizzled in olive oil

Published by Dougal under Food

At the weekend I expanded my bread experience a bit more, with some ciabatta. They’re a long time in the making — twenty-fours for the ferment and a few more to actually make the bread — but they’re definitely worth it to start the week in style. The recipe makes four loaves, which is quite enough for us. Any more and I would have run out of space in the bowl and on the baking tray.

Lunch today was a half ciabatta with tomato, basil and mozzarella. This evening we had more ciabatta, drizzled in olive oil and covered in tomato and bacon. Helen’s brother was supposed to pop round to take one home after a hard night’s playing, but he never turned up. We can only suppose he forgot and went out to the pub. He doesn’t know what he’s missing!

For tomorrow I am going to make some mint-infused milk, for an orange and mint loaf that I’ve had my eye on for some time. I must remember to buy some oranges on the way home from work tomorrow.

One response so far

Aug 16 2008

My allegory is bigger than yours

Published by Dougal under Culture, Politics, Religion

If you’ve not heard about the Jewel of Medina story, read the story about “the next Satanic Verses. My favourite quote was the university professor claiming:

You can’t play with a sacred history and turn it into soft core pornography.

Well, I’m pretty sure you can. If you can film The Passion of the Christ it should be possible to do anything. But even if you can’t, we’ll just wait for them to film Song of Songs instead, right? No need to turn it into pornography at all.

Comments Off

Aug 15 2008

Finally! Done something at the festival!

Published by Dougal under Comedy, Food, Reviews

We finally got our act together and saw some stuff at the festival on Wednesday.

  • Aeneas Faversham Forever by The Penny Dreadfuls

    These guys have been steadily building quite a name for themselves, mining the rich seam of Victorian-era comedy. In previous years the show has been sketch-based, but this time there was a reasonably neat plot holding it all together. Lots of opportunity to play up conventions of Victorian melodrama, sinister cults, Holmes detective stories and such. Also, pant-splittingly funny.

  • The Rat Pack, Live! (I can’t find a link for these guys anywhere… or at least, not a definitive one. Everyone seems to do these Sinatra et al tribute shows.)

    A reasonably short show, with three guys playing the parts of Frank Sinatra, Dean Martin and Sammy Davis Jr and three gals as the Berelli sisters. It was one of the harder tribute acts I’ve seen, because the three guys looked so incredibly young. When “Dean Martin” came out drunk and dishevelled halfway through the show he looked more like a rebel schoolboy than a Vegas superstar. Music was still helluva fun though.

Between the shows we went to a restaurant, but ran out of time for a final course. Thankfully the jazz show was quite short and there was still time to nip out for pudding later:

  • Black Bo’s is a vegetarian restaurant on Blackfriar Street that doesn’t get the popular acclaim of David Bann’s on the next street along. Bann’s is not my kind of place — too cold and severe, I think. Black Bo’s is more relaxed and casual.

    I had a bit of problem deciding which of many dishes to have. (Helen went for two starters in the end, if I recall correctly.) Eventually I trumped for the “baby corn balls” because I couldn’t work out what that meant. It turned out to be breadcrumbed balls of brie with lumps of baby sweetcorn inside. Incredibly good.

  • We visited The Outsider after the second show. I had the chocolate brownie with strawberry shortcake ice cream. It was really good. I wish there had been more of it, and more space in my stomach too! Service was a bit sleepy but so was I. A magic portal back to my bed would have been ideal after all that.

Comments Off

Aug 15 2008

Censorship, Frank Zappa and George Carlin

Published by Dougal under Politics

Via Calum’s Tumblr blog — Frank Zappa on CNN’s Crossfire in 1986:

Includes hilarious “argumentum ad hitlerum” by John Lofton, sitting to the left of Zappa. Zombie Hitler lives!

And here’s George Carlin on those 7 dirty words:

Comments Off

Aug 13 2008

Home to the family, for the weekend

Published by Dougal under Family, Films, Friends

Does rent control really mean you can get an apartment large enough to film a trendy sitcom in? Will it be a steal? Two old friends are going to New York to find out, and there was a ceilidh at the weekend in their honour. Nick came along too, as there was apparently a surfeit of women and they needed men to even up the numbers. What wasn’t really explained was that most of these women were old ladies or nursing mothers who sat at the side chatting anyway. So actually, in a terrifying first for dance events, there seemed to be significantly more men on the floor than women.

Next day Helen made another Nigella recipe for breakfast. She hasn’t blogged it yet so I won’t reveal more. I didn’t particularly like it. :-( Nick and I returned to Edinburgh mid-afternoon. I was quite impressed with my ability to guide him to the flat by sheer guesswork. Well, this should be the right direction…

I got home on Sunday afternoon and watched Blade Runner (the director’s cut). I’m quite keen to know what Ridley Scott came up with for the recent Final Director’s Cut For Real This Time edition. Also, I’ve never seen the original version with the infamous voice-over. It sounds hilariously bad, and I’ve read quotes from Harrison Ford saying that they kept on dragging him back to record more and more appalling monologue, and every time he would go, kicking and screaming. I have also never seen one with the “happy ending” that Wikipedia mentions.

Comments Off

Aug 12 2008

Spicy bread as a gift

Published by Dougal under Culture, Food, Friends

Helen’s having some picnic lunch thing at work tomorrow. I don’t really know the details of it. But they all have to take something in. So I volunteered to make some bread for her to take in, even though I won’t be there. I’ve met a few of her colleagues so I thought it would be a nice thing to do.

I decided to try the Spicy Moroccan Rolls again — I made them last for the flatwarming party. Come to think of it, that means I missed out on eating most of them last time too! They’re quite small and a wee bit intense. I imagine they’ll travel quite well. I hope they go down well.

Tomorrow evening we’re going out for festival stuff — Aeneas Faversham Forever, The Rat Pack — and a meal with friends at Black Bo’s. The former lot are friends and acquaintances from university, and Helen’s brother is playing saxophone with the latter. Should be a good night!

4 responses so far

Aug 10 2008

Movie audience participation and games

Published by Dougal under Films

There’s a drinking game for Withnail and I that involves matching the characters, measure for measure (or at least trying) which I’m sure has been the ruin of many a poor boy.

There’s also some movies which encourage interaction — I’m thinking specifically of The Rocky Horror (Picture) Show, which encourages dressing in drag and shouting “slut!” at the screen, among other things.

So why not food participation too? Eat noodles with Deckard in the rain. You’ll never forget it.

Comments Off

Aug 08 2008

Watchmen comic

Published by Dougal under Books, Reviews

Watchmen by Alan Moore. (That’s the terrifying looking gent in the photo, that looks like Fagin.) One of those stories that was said to revolutionise the graphic novel industry when it appeared, to raise the bar to a significantly higher level. I can’t really comment on this because I don’t have much experience with what comics were like at the time. There’s always a tendency to look at something that was groundbreaking at the time and think “so clichéd” — be it Tolkien, William Gibson or the music of the Beatles. But it is complex and interesting so it probably made quite a splash when it was released.

Zombie Alan Moore
Zombie Alan Moore
© Loz Pycock

It’s about superheroes. Well, how superheroes would be if they were real. The Batman style of superhero, that doesn’t have fantastical powers. And it’s about the end of the world.

I really enjoyed it, though I found some of the plot not as clear as it could be. Maybe I just read too fast (har har, I’m actually a really slow reader). The character of Rorschach was particularly good — it’s so rare you get to feel sympathy for someone so incredibly antisocial and unsympathetic. Christopher Brookmyre can do it too, but not many people can make you feel that way.

There’s a lot in the book, and I know there will be more to find if I get a chance to read it again (it wasn’t my copy, but borrowed, and there were two people in the queue behind me to get afterwards). The same figures and motifs repeated again and again — the smiley face, the quote that inspired the title, the Hiroshima silhouettes.

But for all its high-brow seriousness it’s still comic too; there’s still humour there. I don’t know the name for it, but there’s a technique that seems most noticeable in comics, where two things are happening at once, and the visuals for one are overlaid with the voices for another, so that each comments on what is happening. Sometimes it’s done in a serious way — the newspaper salesman and the pirate story, for example — but other times it’s just for the sheer hilarity of juxtaposition. It’s the technique that is ideal for sending up sex scenes, it seems.

Below, there’s a little clip of my introduction to Watchmen, including Alan Moore narrating some of Rorschach’s thoughts. Enjoy.

Comments Off

« Prev - Next »