Saturday, October 1, 2011

@ConalElliott re: What resources & practices (teaching Haskell)

Conal Elliott asks: What resources & practices would you recommend for helping a group of Java & C++ programmers learn to work in Haskell? I saw the question first on Twitter, but my compression skills were not up to the task of answering there.

I have two recommendations: teach them the simplest definitions of the fundamentals; read programs with them, out loud, like children's books, skipping nothing.

These steps are often passed hurriedly, by teachers so steeped in a subject they don't realize how different their worlds are, by students eager to build things as quickly in a new programming language as they do in the old. Most likely, the students will assume that they just need to learn new syntax to be off and running. Indeed, I am sure they are capable, self-motivated software professionals and that they would succeed in learning Haskell, just without the deeper understanding that can make it such a joy.

As a test, ask your students to write down the definition of 'type'. I'll bet that their answers will be longer than 'set' and include some mention of bytes, words and big-endian. We were all trained to be mechanics instead of drivers, because all we had were go-carts.

C and its children will have left clutter in their minds. Types will be obstacles, efficiency a drug, correctness assured by machismo. They will gloss over code without really reading it, trying to fit it into an existing model. Saying things out loud helps slow things down, forces them to make connections between symbols, words and definitions so fundamental they are rarely written down. (I backtracked through Paul Hudak's book for hours trying to find out how to say '::'; newcomers ask pretty regularly in #haskell.)

Make sure they know all the places that patterns can appear in code and how they work. Make sure they know that data constructors are functions. Have them verify that with :type in GHCi. And that type constructors are functions, verifying with :kind. They should be familiar with the syntax and semantics of higher-order types before they meet IO, so that they understand it is not magic.

Lists, recursion, functional algorithms, none of these will be challenges, but constructs they have not seen before will give them much more trouble if they cannot deconstruct them to primitives. I cannot imagine Conal omitting such fundamental semantics from his lessons, but I can easily imagine both teacher and students, excited to build new stuff, skimping on the exercises necessary to flush out the old foundations and cement the new.

Sunday, September 11, 2011

Two Degrees from 9/11

On the morning of September 11, 2001, I didn’t board a bus to New York City, and in not doing so, buffered myself from a world of hurt.

I wasn’t clever or prescient, just lucky. I was at the bus stop, I’d seen the bus and flagged it down. But just then, two women jogging by stopped and asked if I had heard what happened. I wanted to keep eye contact with the driver, but the anxiety in their voices made me turn and listen. I glanced back to the driver as he slowed, saw him looking for confirmation, but I didn’t signal him again and he drove on.

I went back home, turned on the TV and soon saw the first tower fall. Had those ladies not happened by, I might well have seen that tower fall from the bus instead.

One friend was not so lucky. He was at jury duty that morning, just ten blocks away from the towers. He saw both towers fall as he walked back to his office in SoHo, breathing the first fumes of the fires, crying uncontrollably at the insanity. Days later, he discovered that a good friend and colleague had been high up in a tower, unable to evacuate. That same victim was actually the boss of another friend of mine, who then had to step up and fill that position.

Another friend was a SCUBA instructor who had trained dozens of NY firefighters to dive. Over a dozen of his students died in the collapse.

Earlier that year, I had attended the wedding of a diver I knew, held at Windows on the World, the restaurant at the top of the north tower. He and his new bride were devastated that so many of the restaurant staff they had worked so closely with to plan the event were lost.

It seemed that everyone lost someone, except for me. My connections were always indirect, like some tragic form of the Kevin Bacon game where I was always degree two. I do not know how much that separation lessened the blow, but it was significant.

On Friday, I went to the NJ side of the Hudson River near the Lincoln Tunnel to see the damage for myself. Though still several miles away, the plume of smoke was trivial to spot, and the lack of that distinctive skyline was like a splinter in my mind.

Still, I did not find myself overwhelmed by anger and grief, like those more closely linked. I looked at New York City, not the way you look when you’ve grown up in a place, but with the eyes of a tourist. The New York metropolitan area is huge. Standing on the palisades, I could see a dense urban landscape, seemingly extending to infinity in all directions.

Suddenly, all I could think of was how little physical damage the attacks had done. Perspective has that effect. The WTC towers were so huge, their presence swamped the mind, especially as one got closer. Just standing at the base and looking up, it felt like they were arching over you instead of going straight up. Their destruction was equally overwhelming. But from where I stood on the palisades, with two degrees of separation in my pocket, I could focus on the thousands of huge buildings, housing millions of people for miles around and see that they were all fine.

I’m not saying the impact wasn’t real, even for someone of degree two. Business dried up and I took advantage of a job offer in San Diego, where I’ve been ever since. All my friends mentioned above stayed and went through some hard times. I sometimes wonder, if I had caught that bus, would I have been degree one, and what might have been different as a result.