Hask范畴下:‘每个类型是范畴’是否成立?Int态射如何定义?
Awesome question—let's unpack this clearly, using your Haskell examples as a guide.
First, let's clarify your Str category example
You mentioned the Str category where Obj(Str) is a singleton set, Hom(Str) consists of all strings, and composition is the (++) operator. This is a classic category theory construction: every monoid corresponds exactly to a category with one object. Here's how it maps:
- The single object is just a placeholder (we can call it
*—it doesn't matter what it is, just that there's only one) - Each string is a morphism from
*to* - Composition of morphisms is exactly the monoid operation (
++for strings) - The identity morphism is the empty string
"", since it satisfies the identity law:"" ++ s = s ++ "" = sfor any strings.
Can Int be a category, following this model?
Your initial phrasing says "Int is the category of all integers"—let's adjust that to fit the Str example's pattern. For Int to form a category like Str, we need to pick a monoid structure on integers (since Str uses the string monoid). Integers actually have two common monoid structures we can use:
- Additive monoid:
- Morphisms are all integers
- Composition of two morphisms
mandnism + n - Identity morphism is
0(since0 + n = n + 0 = nfor any integern)
- Multiplicative monoid:
- Morphisms are all integers
- Composition is
m * n - Identity morphism is
1(since1 * n = n * 1 = n)
If you instead meant "a category where every integer is an object", that's a discrete category: each integer is its own object, and the only morphisms are the identity morphisms (each integer maps to itself, no other morphisms exist). This is a valid category too, but it's a different model than your Str example.
So does the proposition "each type is itself a category" hold?
It depends on how we define the mapping from types to categories:
- If we follow the Str example (monoid → single-object category): No, not every type is a category—only types that have a monoid structure (either built-in or defined by you) can form such a category. For example, a custom type like
data Color = Red | Green | Bluedoesn't have a default monoid operation, so it can't be turned into this kind of category unless you define one. - If we use the discrete category model (each value of the type is an object, only identity morphisms): Yes, every type can be a discrete category—we just take all values of the type as objects, and add the required identity morphisms for each object.
To wrap up: Int category morphisms (based on your Str example)
If we go with the monoid→single-object category model (matching how you described Str), the morphisms in the Int category are exactly the integers themselves, with composition being either integer addition or multiplication (whichever monoid structure you choose).
内容的提问来源于stack exchange,提问作者user5158149

