Lately, I’ve been thinking more and more about something that would be nice to have in GHC.

Consider the Predicate type from HMock:

data Predicate a = Predicate
{ showPredicate :: String,
showNegation :: String,
accept :: a -> Bool,
explain :: a -> String
}

The purpose of this type is to be a function a -> Bool that can also explain itself. That is, you can get Strings to explain what it’s testing, and why a particular argument matches or not. There are three important things to know about Predicate:

  1. It’s important that Predicate works on arbitrary types…


I’ve put together a neat example lately of using FRP (Functional Reactive Programming) to cleanly separate and model the interactions of the pieces of an interactive application: in this case, an RPN (Reverse Polish Notation) calculator. In this article, I present the Haskell code for this application using the Reflex FRP library and the CodeWorld graphics API.

An RPN Calculator

Because CodeWorld is a relatively low-level graphics API, we’ll be reinventing abstractions like numeric entry fields. Don’t think that’s a fundamental part of FRP! Indeed, libraries like reflex-dom provide you all the power of traditional high-level component libraries using the same FRP. …


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.

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!

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…

Chris Smith

Software engineer, volunteer K-12 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