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 \cong id_{\{ *\}}$ and $gf \cong 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 \cong id_{ \{ * \} }$ and $g^\prime \circ f^\prime \cong id_A$.
$f^\prime \circ g^\prime \cong id_{ \{ * \} }$ follows from $f^\prime \circ g^\prime = id_{ \{ * \} }$ (because there is only one function ${ * } \rightarrow { * }$).
From $gf \cong 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!