Being a Compleat Field Guide to the Wild & Wondrous Beasts of Type Theory
Composed & Illuminated by The Society of Pure Functional Naturalists
Turn the page ↓
Plate I
A Bestiary of Type-Level Beasts
Six specimens of remarkable provenance, gathered from the deepest forests of category theory and presented here for the curious naturalist.
Pl. I · fig. 1
The Monad Dragon
Phylum: Monad · Order: IO · Family: Endofunctor
A great winged beast that swallows side-effects whole and exhales them only when bound. Its scales are sequential; its breath, >>=. Beginners are advised to approach with a Just.
Guardian of the structural threshold. She poses a single riddle — preserve thy shape — and devours those who answer with mutation. Her gaze lifts pure functions into context.
fmap :: (a -> b) -> f a -> f b
Pl. I · fig. 3
The Lens Hydra
Phylum: Optic · Order: Profunctor · Family: Van Laarhoven
Cut off one head and two grow back — one for getting, one for setting. Each head focuses upon a different field of the record. Composition of heads is associative; this is its only mercy.
Reborn from the ashes of effectful arguments, this radiant bird applies many to many in parallel. It demands no sequence, only context. Its plumage shimmers with pure liftA2.
A creature of three minds — Eq, Show, and Ord — bound into one body by the ancient covenant of instance. Each head dispatches by inference; the body is parametric.
class Eq a where (==) :: a -> a -> Bool
Pl. I · fig. 6
The Lazy Kraken
Phylum: Thunk · Order: Suspended · Family: WHNF
It dwells beneath the runtime, refusing all evaluation until forced. Its tentacles are infinite lists; its mouth, the demand-driven reduction. Beware the space leak in its wake.
take 5 [1..] :: [Int]
Plate II · A Treatise
De Transformatoribus Monadicis
Or, A Reasoned Account of the Stack-Dwelling Beast Which Layers One Effect Upon Another
Much has been written, by les naturalistes of our age, of the great solitary monads — the Maybe of doubtful regions, the IO of the unclean shores, the State of the murmuring hinterland. Yet the curious traveller will, sooner or later, encounter a creature of compound nature: a beast that bears within itself another beast, layered like the strata of an ancient sea-cliff. This is the Monad Transformer Stack, and it is the subject of our present plate.
The Monad Transformer is not, properly speaking, a monad. It is rather a functor of monads1 — a creature whose office is to take some inner monad m and bestow upon it new powers, while preserving the bind of its host. We write this beast in the customary type-theoretic notation:
newtype StateT s m a = StateT { runStateT :: s -> m (a, s) }
Observe how the inner m is suspended within the outer structure as a thread of pearls upon a string. The stack-dweller demands an offering — a lift — from those who would invoke its inner powers from without. This offering is the price of admission to the lower chambers.
“The transformer is the bridge between two worlds; it speaks the dialect of both, and the accent of neither.”
In the wild, the stack-dweller is most often spotted layered three-deep: StateT s (ReaderT r (ExceptT e IO)). Such a creature, when bound, conducts itself with an admirable stoicism — threading state, environment, exceptions, and I/O through a single do-block as though it were the most natural thing in the philosophical world.2
The Society has long debated whether this creature ought to be classified with the dragons (the IO) or with the more diminutive Maybes. We hold the view, against the objections of certain algebraïstes, that the transformer is its own genus — neither dragon nor maybe, but a chimerical builder of compound creatures, whose only true kin is the categorical free monad.3
— Submitted for review, this 21st day of March, in the year of our reduction MMXXVI.
Plate III · The Annals
A Sightings Log
A chronological accounting of notable creature emergences in the long history of the language.
1990Haskell 1.0
The Original Beast
creature spotted: Lazy Evaluator, Pure Birth
First catalogued in Portland; reports describe a slow-moving creature that refuses to evaluate any argument it has not been explicitly asked for. Appeared shy. Subsisted on lambda calculus.
1998Haskell 98
The Standardisation
creature spotted: Type Classes, Stable Habitat
A council of naturalists agreed upon the creature's principal anatomical features. The beast was, for the first time, given a written description that all field guides could share.
A modest but well-received update. The beast learned new manners and acquired a hierarchical territory. Reports of it dwelling in nested modules became commonplace.
2014GHC 7.10
The Foldable / Traversable Migration
creature spotted: Applicative as Superclass
A great migration was observed: every Monad shed its old skin and assumed the form of an Applicative. Many existing field-guides had to be rewritten. The beasts, however, seemed unperturbed.
2021GHC 9.0
The Linear Awakening
creature spotted: Linear Types, Restricted Use
A new species was glimpsed at the edge of the forest: a beast that consumes its argument exactly once. Slim, severe, and deeply unfond of duplication. Sightings remain rare.
2024GHC 9.10
The Modern Bestiary
creature spotted: Type-level Programming, Refined
The beast's anatomy is now so well-understood that it can be described entirely at the type level. Naturalists report being able to reason about a creature's behaviour without ever seeing it run.