Categories, categories of linear maps and homomorphisms The concept of categories and morphisms were introduced to us today in our Linear Algebra course. I haven't taken abstract algebra yet so this lecture confused me quite a bit. As far as my understanding goes, a category consists of the following:


*

*A class of objects

*A class of morphisms given any 2 objects from the category

*An identity morphism given an object

*A way to compose 2 morphisms


A few examples that were given by our professor that he claimed would be relevant in the class were the category of vector spaces with linear maps as morphisms and the category of linear maps. But he never explored these concepts in detail and just skimmed over them. 
Why must the morphisms of the category of vector spaces have to be linear maps? Why not functions that are non-linear? I have eventually, after trying to prove that they must be linear, think that it is only for the sake of convenience. Is this correct?
And I am quite confused about morphisms of the category of Linear maps (between vector spaces). Does it mean that the morphism takes linear maps as input and outputs an other map in the category?
And in general, do morphisms need only be associative or are there other resitrictions?
I have no prior experience in abstract algebra so please consider me a layman. A few might examples might help.
Thank you
 A: It is by definition that the maps in the category of vector spaces are linear maps. The full description of the data defining the category of vector spaces and linear maps is, after fixing a base field (such as the real numbers $\mathbb{R}$):


*

*Objects: vector spaces over $\mathbb{R}$.

*Morphisms: Set $\operatorname{Hom}(V, W) = \{f : V \to W \mid f \text{ is } \mathbb{R}\text{-linear}\}$.

*Composition: For $f \in \operatorname{Hom}(U, V)$ and $g \in \operatorname{Hom}(V, W)$, the composition $fg$ in the category is defined to be the composition of functions $f \circ g$.


Now you need to check that this data is indeed a category: that composition is associative, that composition lands in the correct set (for the above example, we need $f \circ g$ to be a linear map $V \to W$), and that an identity morphism $\operatorname{id}_V \in \operatorname{Hom}(V, V)$ exists for each object $V$.
Here are some other examples of random categories we could define:


*

*The category of vector spaces and linear isomorphisms. (Same objects as above, but fewer morphisms).

*The category of vector spaces, where the only morphisms are the identity morphisms from an object to itself. (Same objects as above, but a pretty useless category).

*The category of sets and functions.

*The category where the objects are the natural numbers $\mathbb{N} = \{0, 1, 2, \ldots\}$, the morphisms $\operatorname{Hom}(n, m)$ are the set of $m \times n$ matrices, and composition is matrix multiplication.

*The category with a single object $x$ and a single morphism in $\operatorname{Hom}(x, x)$.


There are many things that are categories, some useful, and some not. But the defining data are objects, morphisms, and composition. Then you need to check that the conditions hold. Here are some non-examples of categories:


*

*The category with a single object $\mathbb{R}$, where morphisms $\operatorname{Hom}(\mathbb{R}, \mathbb{R})$ are polynomials of degree at most 2, and composition in the category is composition of functions. (The composition of two quadratics can be a degree-4 polynomial, so this is not a category).

*Suppose we have three objects $A, B, C$, identity morphisms $\operatorname{id}_A, \operatorname{id}_B, \operatorname{id}_C$, and the only other two morphisms in the "category" are $A \to B$ and $B \to C$. Then no matter how composition is defined, this can never be a category, since composing those two morphisms should have given us a morphism $A \to C$.

A: Your set of morphisms between two vector spaces $V$ and $W$ could be the set $\{x: x \text{ is a red fruit that grows in spain}\}$ and you would still get a category if you manage to define composition. It can literally be any set you want as long as you define what it means to compose two morphisms. You can't prove that any category with objects given by vector spaces has linear maps as morphisms. Your set of morphisms between two objects has no relation to functions in general. That's the power of category theory. And yes your definitions get the gist of it right, the composition has to be associative aswell though, i.e $(f \circ g) \circ h = f \circ (g \circ h)$ but those are the only requirements.
Most oftenly we require that $\text{Hom}(x,y)$ (the class of morphisms between two objects $x$ and $y$) is a set but category theorists usually don't really give a crap about size restrictions in my experience. If you want to explicitly say that $\text{Hom}(x,y)$ has to be a set for all $x,y$ then you say that your category is locally small.
A: A category $\mathcal C$ has objects and morphisms. Nothing is said a priori about the nature of the objects. Given a pair $(A, B)$ of objects of $\mathcal C$, there exists a set $\mathrm{Hom}(A, B)$ of morphisms from $A$ to $B$. Note that $f$ is a morphism of $A$ in $B$ by using the diagram $f: A \longrightarrow B$ or by writing $f\in \mathrm{Hom}(A, B)$. The following conditions are required for the morphisms of a category.


*

*If $f$ is a morphism of $A_1$ to $A_2$ and $g$ is a morphism of $A_2$ to $A_3$, there is a composition morphism, denoted $gf$, of $A_1$ to $A_3$.

*If $f$ is a morphism from $A_1$ to $A_2$, $g$ is a morphism from $A_2$ to $A_3$ and h is a morphism from $A_3$ to $A_4$, then we have  $(hg)f = h(gf)$.

*For every object $A$ there exists a morphism $e: A \rightarrow A$, called the identity of $A$, such that for any morphism $f: B \rightarrow A$ we have $ef = f$ and for any morphism $g: \rightarrow B$ we have $ge = g$.


*

*Category $\mathrm{Ens}$ of sets.
The objects are the sets and the morphisms of $A$ in $B$ are the applications of $A$ in $B$. The identity of $A$ is the identity  application defined by $e(x) = x$ for any element x of $A$.

*Category whose objects are the numbers $1, 2, 3. $  Morphisms other than identities are $u: 1 \rightarrow 2, v: 2 \rightarrow3$ and $w: 1 \rightarrow3.$ The morphisms $u$ and $v$ are composable and we necessarily $vu = w$ because $w$ is the only morphism going from $1$ to $3.$ 

*We can think of it as a transformation. For example, the "mincer" morphism that transforms  cow into a minced steak, which can be represented as follows:
$$
\mathrm{Cow} \longrightarrow \mathrm{Steak}.
$$
