diff --git a/libraries/ghc-internal/src/GHC/Internal/Control/Category.hs b/libraries/ghc-internal/src/GHC/Internal/Control/Category.hs index 01176aa12b5d40cb0a4ec56e83dd72e89efb0ce3..beb612b4590c49e1fa622ae957b6d8f891abc4e7 100644 --- a/libraries/ghc-internal/src/GHC/Internal/Control/Category.hs +++ b/libraries/ghc-internal/src/GHC/Internal/Control/Category.hs @@ -49,6 +49,26 @@ infixr 1 >>>, <<< -- f . g = \\x -> f (g x) -- @ -- +-- Isomorphisms form a category as well: +-- +-- @ +-- data Iso a b = Iso (a -> b) (b -> a) +-- +-- instance Category Iso where +-- id = Iso id id +-- Iso f1 g1 . Iso f2 g2 = Iso (f1 . f2) (g2 . g1) +-- @ +-- +-- Natural transformations are another important example: +-- +-- @ +-- newtype f ~> g = NatTransform (forall x. f x -> g x) +-- +-- instance Category (~>) where +-- id = NatTransform id +-- NatTransform f . NatTransform g = NatTransform (f . g) +-- @ +-- -- Using the `TypeData` language extension, we can also make a category where `k` isn't -- `Type`, but a custom kind `Door` instead: --