TITLE: Proof that retract of contractible space is contractible
QUESTION [14 upvotes]: I'm reading Hatcher and I'm doing exercise 9 on page 19. Can you tell me if my answer is correct?
Exercise: Show that a retract of a contractible space is contractible.
Proof:
Let $X$ be a contractible space, i.e. $\exists f :X \rightarrow \{ * \}$,$g: \{ * \} \rightarrow X$ continuous such that $fg \simeq id_{\{ *\}}$ and $gf \simeq id_X$ and let $r:X \rightarrow X$ be a retraction of $X$ i.e. $r$ continuous and $r(X) = A$ and $r\mid_A = id_A$.
(Edited using Anton's answer)
Define $f^\prime := f\mid_A$ and $g^\prime := r \circ g$.
Now we need to show $f^\prime \circ g^\prime \simeq id_{ \{ * \} }$  and $g^\prime \circ f^\prime \simeq id_A$.
$f^\prime \circ g^\prime \simeq id_{ \{ * \} }$ follows from $f^\prime \circ g^\prime = id_{ \{ * \} }$ (because there is only one function $\{ * \} \rightarrow \{ * \}$).
From $gf \simeq id_X$ we have a homotopy $H: I \times X \rightarrow X$ such that $H(0,x) = g \circ f (x)$ and $H(1,x) = id_X$. From this we build a homotopy $H^\prime : I \times A \rightarrow A$ by defining $H^\prime := r \circ H \mid_{I \times A}$. Then $H^\prime (0,x) = g^\prime \circ f\mid_A (x)$ and $H^\prime (1,x) = id_A$.
I'm particularly dissatisfied with the amount of detail in my reasoning but I can't seem to produce what I'm looking for. Many thanks for your help!

REPLY [6 votes]: Your real questions have allready been answered. Here I give an alternative proof, demanding some familiarity with categories. It illustrates how convenient 'abstract nonsense' can be. I go out from retraction $r:X\rightarrow A$ and inclusion $i:A\rightarrow X$ with $ri=1$.
The contractible objects in category $\mathbf{Top}$ are exactly the
terminal objects in category $\mathbf{hTop}$. If $X$ is a terminal object in $\mathbf{hTop}$, then for every object $Y$ the 
homset $\mathbf{hTop}\left(Y,X\right)$ contains exactly one arrow.
Let us denote this arrow by $\left[c\right]$. Then homset $\mathbf{hTop}\left(Y,A\right)$
contains arrow $\left[r\right]\left[c\right]$. Now let $\left[f\right]\in\mathbf{hTop}\left(Y,A\right)$.
Then $\left[i\right]\left[f\right]\in\mathbf{hTop}\left(Y,X\right)$
so $\left[i\right]\left[f\right]=\left[c\right]$. Then we find $\left[f\right]=\left[r\right]\left[i\right]\left[f\right]=\left[r\right]\left[c\right]$
demonstrating that $\left[r\right]\left[c\right]$ is the only element
of $\mathbf{hTop}\left(Y,A\right)$. Proved is now that $A$ is terminal
in $\mathbf{hTop}$, hence contractible in $\mathbf{Top}$.

It can be done even shorter:
$\left[\right]:\mathbf{Top}\rightarrow\mathbf{hTop}$ is a functor
and functors respect retractions (=arrows that have a right-inverse). So if $r:X\rightarrow A$ is a retraction
in $\mathbf{Top}$ then $\left[r\right]:X\rightarrow A$ is a retraction
in $\mathbf{hTop}$.
If $\left[r\right]:X\rightarrow A$ is a retraction and
$X$ is terminal then $\left[r\right]$ is an isomorphism, hence $A$
is terminal. (This is true in every category, but to maintain the line of the proof I keep on using the notation $\left[r\right]$.)
Proof of that: some $\left[s\right]:A\rightarrow X$ exists with $\left[r\right]\left[s\right]=1$;
then $\left[s\right]\left[r\right]:X\rightarrow X$ and the identity
is the only endomorphism here, so $\left[s\right]\left[r\right]=1$.