Introduction to Haskell

Today I gave a presentation about my personal favorite programming language: Haskell. This is what I presented, which is also available in PDF format.

What is Haskell?

Before we get into how to actually build stuff in Haskell, you should have at least a basic understanding of what Haskell is, and how it differs from the programming languages you’re likely to already know.

Haskell is a lazy, purely functional programming language. This means a few things:

Laziness: Last-Minute Evaluation

One of the ways that Haskell improves the performance and expressiveness of code is through laziness. This means that nothing you write in Haskell is evaluated until it has to be. Let’s look at an example from GHCi, the Haskell interpreter:

> let x = 3 + 7
> x
10

You might think that the 3 + 7 expression is evaluated in the first line, but it’s not. In fact, evaluation doesn’t happen until the second line. The first line is instead a promise to evaluate x to that particular value when it’s needed. Until x is called for, the evaluation doesn’t happen, and if x is never called for, the evaluation never happens at all.

5 Cool Things About Rust

I wrote this small essay for a presentation in my Senior Seminar class. I have reproduced it here (and made it available as a PDF) in case anyone is interested.

Rust is a safe systems language designed by Mozilla as an alternative to C and C++. It is already being used in the creation of large software systems, including its own compiler (rustc), and a web browser rendering engine called Servo.

Rust focuses on providing language features that guarantee the nonexistence of certain classes of common errors, without impairing program performance. Those errors include:

  • Memory leaks
  • Data races
  • Buffer overflows
  • Segmentation faults

These errors, and others like them, are common and easy to have in existing systems languages like C and C++. The conventional wisdom has long been that avoiding these errors will bring untenable performance penalties. Rust is proof that this isn’t true. Instead of adding runtime checks to avoid these problems, Rust uses a full-featured collection of compiler checks to verify they can’t happen, and then generates efficient machine code without any runtime checks.

In this small essay I will walk through a collection of five Rust features (Cargo, immutable-by-default variables, traits, the borrow checker, and pattern matching) that make creating systems in Rust a joy. They are not the only selling points for Rust, but they should provide a nice introduction to some of the wonderful things that Rust provides, and should hopefully convince you to try it out. If you want to know more, check out http://rust-lang.org.

Room for Squares (Dodecahedrons Too)

A story about a surprising intersection of tabletop roleplaying and topology puzzles.

I’ve been playing Pathfinder with a group led by my friend Anthony for several weeks now. Today our characters (myself a Kitsune Trickster, along with a Half-Elf Druid, an Ifrit Brawler, an Undine Swashbuckler, and a Sylph Arcanist) found ourselves in the home of the Wizard’s Guild of the city of Promise (a silly name invented in a previous campaign). Concerned with the disappearance of their two shock lizard mascots, they sent us quickly to the unexplored chambers of their departed leader. We were told to retrieve the lizards, and if possible figure out how to navigate this part of the guild’s home.

We quickly encountered a problem. The first room found us exiting a door embedded in a pillar that sat in its center. Walking around the pillar we found that the seemingly square room had five sides (although at every point the walls met at right angles). Realizing that there was some non-Euclidean silliness about, I quickly began a map of the rooms as we traveled through them.

Computing and Computers

Can pure computing in the style of Edsger Dijkstra be a gateway to understanding computers?

There was an interesting belief several decades ago, most prominently held by Edsger Dijkstra, that computing as a field could be separated entirely from computers, the machines that engage in computing. The argument went something like this:

  1. The theorems of computing are true regardless of the machine they are implemented on. Put another way, the only machines to be called computers were those machines that could engage in computing, and any such machine is equivalent to any other, save for implementation details
  2. Algorithms, the formal method for defining computation, exist independently of the machines that implement them
  3. Limitations on computation are not truly given by hardware (if they, the limitation is temporal, not technical, in nature) but by the algorithm itself

In other words, while algorithms are not useful unless they have a machine to implement them, the truth of what they are and can do exists independently of such a machine. Thus, the conflation of program and machine, of computing and computer, is wrong.

Write Like A Person

A few suggestions for writing well while you’re still young, from someone who learned late.

I’d like to take a moment to speak to all the students who have just in the last month or so graduated from High School, and who are now preparing to join the workforce or go to university. I’d like to share with you a piece of advice I wish I’d received. Something that took me years to realize independently. It’s about writing. It’s about how to write well and not sound like a jackass; and I never figured it out until I went back and read some of the things I’d written in the past. It’s something that will require a lot of you to forget what you learned in High School: forget the five paragraph format, the hook-thesis-preview opener, the summative conclusion, all of it. It may seem intimidating at first, and so in this small piece I will spend the majority of my time explaining why this is in fact easier for you than everything you’ve learned, and I will attempt to convince you that writing in this way will not only make it easier to write, but will improve people’s reactions to what you’ve written. So what is this suggestion?

Write like a person.

Is This Really Permanent?

Ars Technica has an article out about preserving technology. Read it if you haven’t already. It’s not long, and the topic is important.

Read it? Okay, good.

I liked the article, in case it wasn’t clear, and it got me thinking about the issue of information permanence. In the past our knowledge and experiences (or at least artifacts that act as evidence of them) were inherently preserved to some degree by their medium of expression. Pictures were physical goods, books were physical goods, videos were physical goods. Yet the increasing digitization of human experience makes that experience all the more fragile to the whims of time. Imagine for a moment what would happen if Dropbox disappeared, so that all your data stored there was gone forever. Would you still have your pictures? Would you still have your videos? Your essays? What would remain to you? Maybe you backed it all up and it’s on a hard drive somewhere. Well, imagine it’s 50 years later, and you’ve found that hard drive and you want to take a look and those old pictures and videos. Can you even use it? Do you have a device that can connect to it and read it? Or was the permanence of the physical good a lie?

Surpassing The Hacks

On the history of web development hacks and the path to overcoming them.

Web development history is rife with hacks. Developers have always been looking to push the boundaries while maintaining relative consistency cross-browser, and the pace of developer creativity has consistently exceeded the pace of implementer development. So, hacks.

Goodbye Quora

It is easy to forsake principles for a beloved service, but when is it right, and when should you stop?

I have recently decided, after much consideration and an abundance of time, to leave Quora behind. I have been an active member for several years, and have shared information on there across topics as diverse as Computer Science, the proper use of Tumblr, and elementary school bullying. In that time I have interacted with a number of impressively funny and intelligent individuals, and I am happy to say I have learned a lot about a variety of subjects.

Why then, have I chosen to leave?

Dijkstra’s Writings Available

Reading smart writings written by smart people is an excellent way to get smarter. Here’s new stuff.

Edsger Dijkstra, famous Computer Scientist, is one of my favorite intellectuals. He was a man with strong opinions, who consistently and publicly defended them. His piece “On the Cruelty of Really Teaching Computer Science” stands as one of my favorite pieces of academic writing.

Getting Back

After days of excitement how do you avoid the siren call of old routines?

I returned just yesterday from the Southern California Linux Expo. It was my first time going, and I went with a large group of friends, all of whom but one had also never been. It was a fun time. This post isn’t about the conference though. It’s about what happens when you get back.

Conferences and expos are a time to extract yourself from the world, and have some fun learning new things and meeting new people. There’s a certain joy in the picking of sessions and watching of keynotes. A certain excitement in a conversation picked up with strangers over some tech overhead in passing.