There’s a well-known problem called the Towers of Hanoi, in which n disks, all different sizes, are placed onto three rods to form towers. The goal is to move between various configurations while following two rules.

  1. You may only move one disk at a time, and must place that disk onto a tower before you can pick up a new one.
  2. You may never place a larger disk on top of a smaller disk.

The famous version of this problem starts with all the disks on the first tower, and then asks you to move them all to the last…

I’ve just released HMock 0.3 to Hackage. See the original announcement for more details on the project.

Highlights of this release include:

  • You can now use the WholeMethodMatcher type in an expectation to write a custom predicate that looks at more than one argument at a time when deciding whether to match a method call.
  • You can now add side-effects to methods using whenever. You should prefer to avoid this and use expectations instead, since if you’re not careful side-effects can accidentally match method calls that you weren’t looking for. But occasionally this can be very useful.
  • You can now…

Before COVID-19 left its mark on the world, a group of us met one a month in New York for the “Haskell Cohack”, hacking together on Haskell programming projects of various forms. We had people there to learn Haskell or teach it, to talk about category theory, to work on core libraries, or just to fiddle around with programming problems like Project Euler or Advent of Code. It was great fun! But then this virus shut down the city, and we have missed our monthly meeting ever since.

I’m now reviving the Cohack, but in virtual form. Our first session…

I’ve just released a small update to HMock, the Haskell mock testing framework which I first released following Zurihac. Here’s what’s new in the new version.

Rejecting ambiguous expectations

First, HMock can now reject ambiguous expectations. Suppose had a mock filesystem monad with HMock, and you wrote something like this:

expect $ ReadFile_ anything |-> "some content"
expect $ ReadFile "foo.txt" |-> "foo content"
x <- readFile "foo.txt"

With HMock 0.1, x is "foo content". The more recent expectation matches before earlier expectations. This is often what you want. But Svenningsson et al argue very strongly in An Expressive Semantics of Mocking that…

At the end of Zurihac this year, I released a preview version of HMock, a new library for testing with mocks in Haskell. Let’s talk about what this is, why I wrote it, and how you can use it.

A Toy Chatbot

Let’s suppose I want to write a chatbot in Haskell. I might start with a few types, like so…

newtype User = User String deriving (Eq, Show)
data PermLevel = Guest | NormalUser | Admin deriving (Eq, Show)
newtype Room = Room String deriving (Eq, Show)
data BannedException = BannedException deriving (Show)
instance Exception BannedException

Now I need to log in…

Last November at the Haskell eXchange conference, Simon Peyton Jones announced the Haskell Foundation. This can be understood as many things: an organization dedicated to the hard work of making Haskell more successful and useful, a touchpoint for different parts of the Haskell community to come together and cooperate, and a focus knob to direct general support (financial and otherwise) for the Haskell community and maximize its impact.

SPJ Announcing the Haskell Foundation

I recently decided to become a major contributor to the Haskell Foundation, and I’m writing about the reasons behind my decision. I also hope to encourage others who can easily do so…

I have always loved finding those parts of mathematics where big ideas just pop out almost by accident, appearing fully formed in a surprising and delightful way. Who, for example, could fail to marvel at how topology manages to capture so many unique and striking meanings into words like continuous which can mean very different things just by choosing a different topology in which to interpret the same definition?

Something like this happens in categories by considering limits and colimits. One simply draws a simple picture, follows a simple set of rules, and important ideas pop out. …

Here are two theorems from game theory, which initially seem to contradict each other. By comparing them, we can uncover some hidden nuance in the situation.

Gibbard and Roth face off!

Gibbard’s Theorem: Strategy is Inevitable

The first theorem, initially by Allan Gibbard and generalized by later work by Gibbard and others, showed that any collective decision-making process must have one of three properties:

  1. There are only two possible outcomes.
  2. There is a dictator, who can choose the outcome regardless of any choices made by anyone else.
  3. It is strategic, meaning that the best way to get what you want depends not just on your preferred outcome but also on…


In this article, we’ll develop a Haskell library for continued fractions. Continued fractions are a different representation for real numbers, besides the fractions and decimals we all learned about in grade school. In the process, we’ll build correct and performant software using ideas that are central to the Haskell programming language community: equational reasoning, property testing, and term rewriting.

I posted an early version of this article to Reddit, and I’m grateful to those who responded with insight and questions that helped me complete this journey, especially iggybibi and lpsmith.

Introduction to continued fractions

Let’s start with a challenge. Assume I know how to…

This is the story of an interesting flight of fancy with mathematics. I found it intriguing, and hope you do, as well.

The question

Here’s a fact that comes up in high school mathematics: you can demote multiplication into addition by using logarithms. That is:

That is, you can compute the log of a product, given only the logs of the factors.

To students today, this might seem like just another algebraic identity. But in the age before calculators, it was actually the main reason for a typical high school student to be interested in logarithms at all! Multiplication is more difficult…

Chris Smith

Software engineer at Facebook, volunteer math and computer science teacher, author of the CodeWorld platform, amateur ring theorist, and Haskell enthusiast.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store