# monoid object in "arrows-only" single-sorted definition of a category

There's a way to define a category as "arrows-only" single-sorted.

An object is an identity morphism : a → a

https://ncatlab.org/nlab/show/single-sorted+definition+of+a+category

There are Remarks

Specializations

A monoid is a single-sorted category in which s is a constant function (hence so is t, and they are equal).

So when a monoid object is 5, is it expressed like:

(f → 5)(a → a)

or simply

(a → a)(5)

Thanks.

main :: IO ()
main = do
print $$(\f -> 5)(\a -> a) print$$ (\a -> a)(5)


Thanks.

EDIT: to make the problem clearer, I will quote

Categories for the Working Mathematician, I.1 and XII.5.

I.1

XII.5

• In mathematics, one distinguishes between $\to$ and $\mapsto$. The definition of a map is written using $\mapsto$, not $\to$. Commented Sep 2, 2020 at 11:00

Consider a category $$\mathscr C$$ with a single object $$X$$. Then the one-sorted presentation of $$\mathscr C$$ will have a collection of morphisms $$C = \mathscr C(X, X)$$ and functions $$s, t : C \to C$$ such that $$\forall c \in \mathscr C . s(c) = t(c) = \mathrm{id}_X$$. That is, $$s = t = \lambda c . \mathrm{id}_X$$. The composition of morphisms reduces to a binary operation on $$C$$, because the source and target of each morphism is $$\mathrm{id}_X$$, and $$\mathrm{id}_X$$ also acts as an identity for the binary operation. The definition thus reduces exactly to that of a traditional monoid (albeit one with a class of elements, rather than a set of elements, when $$\mathscr C$$ is not necessarily locally small).

In terms of Haskell, the definition of $$s$$ and $$t$$ is therefore given by \c -> id_X, for some id_X.

Therefore, a one-sorted presentation of a category in Haskell may be described by a Monoid, which we will call X, along with two functions s :: X -> X and t :: X -> X. s and t are both defined by \x -> mempty X. (Here, mempty is the identity for the monoid.)

class Monoid m => OneObjectOneSortedCategory m where
s :: m -> m
t :: m -> m
s _ = mempty
t _ = mempty

-- An example of a monoid as a one-object single-sorted category.
instance OneObjectOneSortedCategory [a]

main = do
-- Prints [], the identity element.
print (s [1, 2, 3])


Alternatively, in Rust:

trait OneObjectOneSortedCategory: Sized {
fn id() -> Self;

fn mul(&self, other: &Self) -> Self;

fn s(&self) -> Self {
Self::id()
}

fn t(&self) -> Self {
Self::id()
}
}

impl OneObjectOneSortedCategory for i8 {
fn id() -> i8 {
0
}

fn mul(&self, other: &i8) -> i8 {
self + other
}
}

fn main() {
println!("{}", 5.s());
}


Since there's still confusion, let me try rephrasing the following quote, which seems to be the issue.

A monoid is a single-sorted category in which $$s$$ is a constant function (hence so is $$t$$, and they are equal).

What does this mean?

If we take a monoid $$(M, \otimes, I)$$, then we can form a single-sorted category $$\mathbf C = M$$. The functions $$s : \mathbf C \to \mathbf C$$ and $$t : \mathbf C \to \mathbf C$$ are both defined to be the constant function $$x \mapsto I$$. Therefore, the category $$\mathbf C$$ has a single object, $$I$$. The composite $$a \circ b$$ of two morphisms $$a, b \in \mathbf C$$ is given by $$a \otimes b$$. The identity is given by $$I \in \mathbf C$$.

Alternatively, take a single-sorted one-object category $$\mathbf C$$. Let $$U$$ be the object of $$\mathbf C$$ (i.e. the value of $$s(x)$$ for any $$x \in \mathbf C$$). We can define a monoid $$(M, \otimes, I)$$, where $$M = \mathbf C$$. Given elements $$a, b \in M$$, we define their multiplication $$a \otimes b := a \circ b$$. We define $$I := \mathrm{id}_U$$.

Therefore, the two presentations are equivalent.

• Thank you, however the answer is too abstract, and it's a bit complicated for me to read and understand. Could you please give me a concise example using rather concrete value such as \a -> a and 5? Also, new line with short sentences helps. Commented Sep 2, 2020 at 10:39
• For instance, in your answer, where are the identity morphisms? Commented Sep 2, 2020 at 10:49
• I've added another sentence, summarising the answer. The idea is that a one-sorted category is exactly the same as a monoid, with two constant functions s and t. (So s and t can be ignored, because the data is already given by mempty). Commented Sep 2, 2020 at 10:51
• @smooth_writing: I've expanded my answer. I think if this doesn't make sense, I would recommend becoming more familiar with categories and monoids first, and ignoring the single-sorted definition, which is an unusual definition. There's no advantage to the single-sorted definition for programming. Commented Sep 2, 2020 at 14:25
• All I meant is that the single-sorted definition is more difficult to understand: it's a clever trick that a category can be described that way, but I'm not sure that it's helpful to use. However, if you like that presentation, the entire book Categories, Allegories is written in this style, which you may be interested in. Commented Sep 3, 2020 at 22:16