This post begins a short series meant to serve as an informal guide to reading Haskell code and translating back and forth with mathematics. It’s meant to help members of r/CategoryTheory understand posts that use Haskell code to convey ideas. My hope is that this series should also find use among Haskell programmers, as exposure to some of the basic methods and terminology used in modern math.…
A recent post on r/haskell solicited help understanding the expression isAllergicTo :: Allergen -> Int -> Bool isAllergicTo = ( . allergies ) . elem where Allergen is a type and allergies :: Int -> [Allergen] . It’s straightforward to rewrite this function pointfully ( ie. with formal parameters in place), but doing so doesn’t help one develope an intuition for thinking about function composition,…
Hand-wavy explanations of my lightning talk of the same title at Mercury’s October 2022 PDX Haskell meetup. Based on “Infinite sets that admit fast exhaustive search” by Martín Escardó. {-# OPTIONS_GHC -Wall -fno-warn-orphans -fno-warn-name-shadowing #-} {-# LANGUAGE DerivingVia, FlexibleInstances #-} module Escardo where import Prelude hiding ( Real ) import Data.List ( find ) import Data.Maybe (…
The sickest experience possible for Haskell development in July 2022 is undoubtedly VS Code with the Haskell plugin powered by Haskell Language Server (HLS). When HLS works for your project, that is. This guide will demonstrate a simpler, lower-featured alternative that hopefully is reliable enough to work with your project in those cases where HLS does not. Changelog 2022-07-26 Add --warnings to…
Set theory is a bit of a trickster. Some of its ideas go back to Plato (forms) and Aristotle (categorical syllogisms), but sets don’t quite capture the objects of these disciplines. Rather, the objects of those disciplines are captured more closely by the concept of classes (as in classifications ). Sets vs. classes? What’s the difference? Why split hares? This blog post will go into how Set…
The beginning of a series wherein we show how to implement selected design patterns from Design Patterns: Elements of Reusable Object-Oriented Software . This week, we take a look at the venerable Abstract Factory pattern. A common question new Haskell programmers have is, “How do I implement <this-or-that> OOP design pattern in Haskell.” These curious and resolute dames and gents are (quite…
Some Haskell classes class Myclass a admit an instance for functions instance Myclass a => Myclass (x -> a) based on the instance for a . All of these instances have a few things in common: (1) they implement the class methods in a straightforward way as mymethod f = \x -> mymethod (f x) , and (2) they are polarizing among Haskell practitioners. The sequel is a case study of why I find such…
A coworker of mine has been kind enough to spend his scant spare time guiding a small group of future Haskellers through Hutton’s Programming in Haskell , assigning weekly problems and judging the solutions submitted along the way. What follows here today 1 is my smart-ass solution to my colleague’s Problem 1 . Executing Programs on Paper Week 1 of the reading group was to read Chapter 1 in Hutton…
I recently had to implement linear regression for a hobby project. As I’d never learned how to calculate it, this was a great opportunity to learn. As I dug in, I saw that I’d need to be making two passes over my data. Let’s see if we can fix that. The Problem Simple linear regression is where we take a set of points in the plane and compute the slope and \(y\)-intercept of the line that…
Recently to a friend, I quipped that it’d be a good exercise towards demystifying Haskell’s IO type to write a comparable IO type in your favorite language. In this blog post, I do that for Java, Javascript, Python, and Scala. TL;DR: Here’s the code . Understanding Functional APIs My favorite way of understanding a type is by looking at its constructors, combinators, and eliminators. But what do I…