patternMinor
Describing the Bool-And monoid in terms of categories
Viewed 0 times
monoidthebooldescribingcategoriesandterms
Problem
Normally I put the question before the context, but in this case I want to admit
the possibility that the context and my understanding nullify the question.
Plus it helps me think through my question.
I recently started reading Category Theory for Programmers (Bartosz
Milewski), and this is my
understanding of categories: they are "algebraic structures" which consist of
objects and arrows/morphisms between those objects. The morphisms have to obey
the laws of associativity, so
$$ a \rightarrow ( b \rightarrow c ) = ( a \rightarrow b ) \rightarrow c $$
And there must be an identity morphism for each object.
Now, Milewski goes on to explain that monoids (which I'm pretty comfortable with
in the set-theoretic sense) are also viewable as categories. This is the part I
am having trouble with. One of the exercises in the book is to consider the
Boolean-and monoid (booleans with the and operator) as a category:
Represent the Bool monoid with the AND operator as a category: List the
morphisms and their rules of composition.
I want to give some examples, which I'll do in a SML (though I'll borrow Haskell names).
The monoid could be described set-theoretically with the following signature:
Further, the monoid for booleans with the and operator would be given as
So, here is my understanding of this monoid as a category and its morphisms: is
it correct?
booleans to booleans
category (I say "an" because isn't the actual identity function
also an identity morphism for the functions, thanks to polymorphic types? Or
does that not count
the possibility that the context and my understanding nullify the question.
Plus it helps me think through my question.
I recently started reading Category Theory for Programmers (Bartosz
Milewski), and this is my
understanding of categories: they are "algebraic structures" which consist of
objects and arrows/morphisms between those objects. The morphisms have to obey
the laws of associativity, so
$$ a \rightarrow ( b \rightarrow c ) = ( a \rightarrow b ) \rightarrow c $$
And there must be an identity morphism for each object.
Now, Milewski goes on to explain that monoids (which I'm pretty comfortable with
in the set-theoretic sense) are also viewable as categories. This is the part I
am having trouble with. One of the exercises in the book is to consider the
Boolean-and monoid (booleans with the and operator) as a category:
Represent the Bool monoid with the AND operator as a category: List the
morphisms and their rules of composition.
I want to give some examples, which I'll do in a SML (though I'll borrow Haskell names).
The monoid could be described set-theoretically with the following signature:
signature MONOID = sig
type m
val mempty : m
val mappend : m -> m -> m
endFurther, the monoid for booleans with the and operator would be given as
structure BoolAnd : MONOID = struct
type m = bool
val mempty = true
fun mappend x y = x andalso y
endSo, here is my understanding of this monoid as a category and its morphisms: is
it correct?
- The objects in the category are booleans (true and false) and functions from
booleans to booleans
BoolAnd.mappendis a morphism from the former to the latter
mappend trueis an identity morphism for the function objects in the
category (I say "an" because isn't the actual identity function
fun id x = xalso an identity morphism for the functions, thanks to polymorphic types? Or
does that not count
Solution
Monoids are one-object categories. The elements are morphisms, monoid multiplication is composition and the monoid identity is the identity morphism.
In the case of Booleans-with-AND the monoid is $M = (\{\top, \bot\}, \land, \top)$. The category therefore has a single object (we could call it $M$) with two morphisms $\top : M \to M$ and $\bot : M \to M$. Composition is given by $\land$ and the identity morphism is $\top$.
To give a little more context, there is a way to view a monoid in such a way that the objects are the elements of the monoid: as a discrete (no non-identity morphisms) monoidal category. Category Theory for Programmers covers the topic of monoidal categories in Chapter 22, "Monads Categorically".
In the case of Booleans-with-AND the monoid is $M = (\{\top, \bot\}, \land, \top)$. The category therefore has a single object (we could call it $M$) with two morphisms $\top : M \to M$ and $\bot : M \to M$. Composition is given by $\land$ and the identity morphism is $\top$.
To give a little more context, there is a way to view a monoid in such a way that the objects are the elements of the monoid: as a discrete (no non-identity morphisms) monoidal category. Category Theory for Programmers covers the topic of monoidal categories in Chapter 22, "Monads Categorically".
Context
StackExchange Computer Science Q#126806, answer score: 2
Revisions (0)
No revisions yet.