HeadlinesBriefing favicon HeadlinesBriefing.com

Actegories and Monoidal Categories in Haskell

Hacker News •
×

Actegories play a central role in optics such as lenses, prisms, and traversals. To understand them, we start with a monoidal category—a category equipped with a tensor product, an associative and unital operation up to isomorphism. The tensor is a bifunctor, and we model a monoidal category in Haskell by parameterising the tensor type ten and constraining the objects with a typeclass, for example Monoid. The unit object is encoded as an associated type Unit ten, and we use the pragma UndecidableSuperClasses to handle the circularity. The associator and unitors become natural transformations, with infix notation for the tensor.

An Actegory is a category that supports the action of a monoidal category, effectively “scaling” its objects by monoidal objects. The action is a bifunctor from the product of the monoidal category and the actegory to the actegory itself, with coherency conditions given by invertible natural transformations relating the action to the tensor and its unit. Simple examples include the self‑action of the cartesian product on Hask or using Either as the tensor.

Actegories form a bicategory: morphisms are monoidal functors preserving the action, and 2‑morphisms are action‑preserving natural transformations. This framework underpins many Haskell optics libraries and offers a categorical foundation for functional programming patterns.