Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Category

Lean: Hale.Base.Category | Haskell: Control.Category

Overview

Abstract category with identity and composition. Uses diagrammatic order (f >>> g = g . f), which reads left-to-right as a pipeline.

API Mapping

LeanHaskellKind
Category classCategoryTypeclass
Category.ididMethod
Category.comp / >>>>>>Method
Fun(->)Type
LawfulCategory class(lawful)Typeclass

Instances

  • Category Fun — the function arrow as a category
  • LawfulCategory Fun — all three laws hold definitionally

Proofs & Guarantees

  • id_compid >>> f = f (via LawfulCategory)
  • comp_idf >>> id = f (via LawfulCategory)
  • comp_assoc(f >>> g) >>> h = f >>> (g >>> h) (via LawfulCategory)

Example

-- Compose functions in diagrammatic (left-to-right) order
(Fun.mk (· + 1) >>> Fun.mk (· * 2)).apply 3
-- => 8  (first add 1, then multiply by 2)