https://xkcd.com/1312/

A lesson from open source software

I've always tried to contribute to open source software whenever I've seen the opportunity, but becoming a maintainer of an open source library gave me some completely new perspectives.

I've used Emacs for almost a decade, and I used Vim before that. Maybe the fact that vi key bindings are just another package in Emacs, called Evil, was one of the reasons I switched to Emacs. I like modal editing, but I don't use Evil. Instead, I use God mode with Emacs key bindings.

At some point, I discovered Doom Emacs, which packed a lot of functionality that interested me compared to other Emacs distributions.

Continue reading →

Can functors solve the expression problem?

An elegant approach to solve the Expression Problem is to use functors and F-algebras to decompose expression types, allowing us to add new variants and new operations easily through modules. The goal is to define a data type by cases while being able to add both new variants and operations without recompiling existing code, and while retaining static type safety.

In Haskell, adding new operations over a fixed set of types is easily done by writing a new function. But adding a new type variant to an existing data type forces you to touch every function that pattern-matches on it. In object-oriented languages the problem is actually reversed.

Continue reading →

Can typeclasses solve the expression problem?

Typeclasses in Haskell roughly correspond to interfaces in object-oriented languages and can be used to solve the Expression Problem. More specifically, since Haskell takes parametric polymorphism quite seriously, typeclasses are more akin to generic interfaces, but also allow ad-hoc polymorphism.

Let's first define an Expr typeclass with const and add as functions. These functions represent types or variants in the Expression Problem.

class Expr t where
  const :: Double -> t
  add :: t -> t -> t
Continue reading →

Can object algebras solve the expression problem?

Another way to solve the expression problem in C# and other object-oriented languages is by using object algebras[1]. Object algebras define a parameterised interface, and a factory that implements that interface.

First, let's define the interface of the Eval operation.

public interface IEval
{
    double Eval();
}
Continue reading →