poetix (old content)

oh build your ship of death

Pangolins in Haskell

The first real program I wrote in Scheme was a version of the old animal guessing game Pangolins. It took me an afternoon. The interesting thing was that it used a fairly pure functional style, consing together the rewritten question tree as it traversed it rather than modifying the updated leaf nodes in place. I thought it would translate pretty easily into Haskell, and so it did.

What the code linked above gives you is the basics of almost any useful program: a data structure, an algorithm for transforming that structure and a user interaction loop.

I started out attempting to do something terribly clever with type classes and separating the tree-rewriting algorithm from the pangolin-game-specific code, and it was an awful mess and trying to figure out the type errors literally gave me a headache (one of those woozy, entering-a-world-of-pain headaches that tells me I should have given up hours ago, and could have solved the problem the simple way several times over during the period I’ve just spent floundering in a quagmire of my own making). If you get out of your depth in Haskell, you find out how out of your depth you are very quickly. But it is a surprisingly accessible language for the mere paddler.