ezyang’s blog

the arc of software bends towards understanding

May, 2010

Punt the Prelude

Conservation attention notice. What definitions from the Haskell 98 Prelude tend to get hidden? I informally take a go over the Prelude and mention some candidates. (.) in the Prelude is function composition, that is, (b -> c) -> (a -> b) -> a -> c. But the denizens of #haskell know it can be […]

  • May 31, 2010

Use The Monoid: A worked example

Attention conservation notice. Equivalent Haskell and Python programs are presented for retrieving values from a data structure using state. We then refactor the Haskell program into one that has no state, just a monoid. A pretty frequent thing a working programmer needs to do is extract some values (frequently more than one) from some data […]

  • May 28, 2010

Bananas, Lenses, Envelopes and Barbed Wire
A Translation Guide

One of the papers I've been slowly rereading since summer began is "Functional Programming with Bananas, Lenses, Envelopes and Barbed Wire", by Erik Meijer, Maarten Fokkinga and Ross Paterson. If you want to know what {cata,ana,hylo,para}morphisms are, this is the paper to read: section 2 gives a highly readable formulation of these morphisms for the […]

  • May 26, 2010

Lazy exceptions and IO

Consider the following piece of code: import Prelude hiding (catch) import Control.Exception main :: IO () main = do t <- safeCall unsafeCall t putStrLn "Done." safeCall :: IO String safeCall = do return alwaysFails `catch` errorHandler --alwaysFails = throw (ErrorCall "Oh no!") alwaysFails = error "Oh no!" errorHandler :: SomeException -> IO String errorHandler […]

  • May 24, 2010

Upgrading to Ubuntu Lucid

Now that term is over, I finally went an upgraded my laptop to Ubuntu 10.04 LTS, Lucid Lynx. The process went substantially more smoothly than Karmic went, but there were still a few hiccups. Etckeeper. As always, you should set AVOID_COMMIT_BEFORE_INSTALL to 0 before attempting a release upgrade, since etckeeper hooks will be invoked multiple […]

  • May 21, 2010

Class Reflections

Last February, I posted about classes that I was going to be taking. Here are some reflections, now that final projects and examinations are over. 6.005: Software Construction. Teaching students how to engineer large software projects is one of the oddest paradoxes that you might encounter in academic life. The institute is certainly capable of […]

  • May 19, 2010

I Hate Patches:
Confessions of an Open-Source Developer

It is a truth universally acknowledged that if you really want a change put into an open source project, you submit a patch along with the bug report. Sure, you might complain that the average user doesn't have any programming experience and that it's unreasonable to expect them to learn some complex system and then […]

  • May 17, 2010

Spring 2010: A Random Walk

Here at the eve of Spring 2010 term, I decided to run this little experiment on my laptop: what files had I modified within the last six months? find . \( -path '*/.*' \) -prune -o -mtime -180 -print The result was north of one-hundred-fifty thousand modified files. Here's the (slightly) abridged version: LaTeX files […]

  • May 14, 2010

Refactoring Haskell code?

I have to admit, refactoring Haskell code (or perhaps even just functional code) is a bit of a mystery to me. A typical refactoring session for me might look like this: sit down in front of code, reread code. Run hlint on the code, fix the problems it gives you. Look at the code some […]

  • May 12, 2010

Nested Data Parallelism versus Creative Catamorphisms

I got to watch (unfortunately not in person) Simon Peyton Jones' excellent talk (no really, if you haven't seen it, you should carve out the hour necessary to watch it) on Data Parallel Haskell (slides). The talk got me thinking about a previous talk about parallelism given by Guy Steele I had seen recently. What's […]

  • May 10, 2010