Skip to content

Instantly share code, notes, and snippets.

@int-index
Last active May 27, 2016 12:52
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save int-index/c84ecda8551f35a8a4b9b47efab1b1f4 to your computer and use it in GitHub Desktop.
Save int-index/c84ecda8551f35a8a4b9b47efab1b1f4 to your computer and use it in GitHub Desktop.
Monoid is a one object Category
{-# LANGUAGE NoImplicitPrelude, GADTs, DataKinds, PolyKinds, FlexibleInstances #-}
import Data.Monoid
import Control.Category
-- A monoid gives a rise to a single-object category.
newtype M m (a :: ()) (b :: ()) = M m
instance Monoid m => Category (M m) where
id = M mempty
M a . M b = M (mappend a b)
-- A category of a single object is a monoid.
instance (Category c, a ~ '(), b ~ '()) => Monoid (c a b) where
mempty = id
mappend = (.)
-- Since we can go both ways and lose nothing along the way, we conclude
-- that a Monoid *is*, in fact, a one object category.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment