Skip to content
Tech News
← Back to articles

Profunctor Equipment in Haskell

read original get Haskell Programming Book → more articles
Why This Matters

This article explores the implementation of Profunctor equipment in Haskell, providing insights into category theory applications within functional programming. By demonstrating how to model complex mathematical concepts in code, it highlights the importance of type safety and compiler verification for advancing reliable software development in the tech industry.

Key Takeaways

Previously: Profunctor Equipment.

To make things more palatable for programmers, I decided to provide a toy implementation of some of the equipments in Haskell. The advantage of this encoding is that it can be verified by the compiler, and I still trust the compiler more than I trust the AI.

A more adequate implementation would require a full-blown dependently typed language, but if we restrict ourselves to just a single category and work only with endo-functors and endo-profunctors, we can get at least some intuitions. If you want to see a more elaborate version, see the proarrows library by Sjoerd Visscher.

The only 0-cell I’ll be using is the Haskell category of types and functions. For vertical 1-cells I’ll use the standard library implementation of Functor , and for horizontal ones I’ll use Profunctor .

A 2-cell in :

is implemented as a natural transformation:

type Cell f g h j = forall a c . h a c -> j (f a) (g c)

The forall serves as a universal quantifier.

The horizontal composition of such cells is given by:

hcomp :: (Functor f, Functor f', Functor g, Functor g'

... continue reading