-
-
Save int-index/c84ecda8551f35a8a4b9b47efab1b1f4 to your computer and use it in GitHub Desktop.
Monoid is a one object Category
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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