If $A$ is compact and $B$ is closed, show $d(A,B)$ is achieved 
Let $A, B$ be subsets of a metric space $X$. If $A$ is compact and $B$ is closed, show that the distance between $A$ and $B$ is achieved.

Attempt at a proof:  
Let $A$ be compact and $B$ be closed. Let $m=d(A,B)=\inf_{b\in B} d(A,B)$. Then, there are two possibilities:
(a) $\exists b\in B$, $d(a,b)=m$. If this is the case, we're done.
(b) $\forall b\in B$, $d(a,b)>m$. In this case,   
there exists a sequence $\{b_n\}\subseteq B:$ $d(a,b_n)\rightarrow m$ as $n\rightarrow\infty$ by definition of infinum. Then there exists a subsequence $\{b_{n_k}\}$: $d(b_{n_1},a)>d(b_{n_2},a)>...$ which is monotonic decreasing. Then note that $d(b_{n_k},a)<d(b_{n_1},a)<\infty$. So it's a bounded sequence. Now I want to show that it has a convergent subsequence that converges to $b\in B$ and then I want to do the same for $A$. And then finally to show that $d(a,b)=m$ in fact. Any clues to how to get there?
 A: If one of the sets is just closed you're plenty of counterexamples to your statement. See the comments. If both sets are compact, we can use something similar to your arguments to prove the result. Just with a bit of careful.
So, consider $X$ a metric space and $A$, $B$ compact subsets of $X$. There exist sequences $\{a_n\}$ in $A$ and $\{b_n\}$ in $B$, such that $$\lim_{n\to\infty}d(a_n,b_n)=d(A,B).$$
In metric spaces the notion of compactness is equivalent to sequential compactness. Then, since $A$ is compact, there is a subsequence $\{a_{n_k}\}$ such that $$\lim_{k\to\infty} a_{n_k}=a\quad\text{ with }\quad a\in A.$$ Note that $$\lim_{k\to\infty} d(a_{n_k},b_{n_k})=d(A,B).$$
Since $B$ is compact, there is a subsequence $\{b_{n_{k_j}}\}$, such that $$\lim_{j\to\infty} b_{n_{k_j}}=b\quad\text{ with }\quad b\in B.$$ Note that
$$\lim_{j\to\infty} d(a_{n_{k_j}},b_{n_{k_j}})=d(A,B),$$
but, since $d$ is a continuous function$^*$, the above equality says
$$d(a,b)=d(A,B)\quad\text{ with }\quad a\in A,\, b\in B.$$
$^*$ Indeed, consider $d:A\times B\to \mathbb{R}$. By considering the metric $D((a_1,b_1),(a_2,b_2))=d(a_1,a_2)+d(b_1,b_2)$ (just as we needed) in $A\times B$ and the usual metric in $\mathbb{R}$, you can see that $d$ is continuous.

As was pointed out in the comments, you can see that $A\times B$ is compact in $X\times X$ with the metric given above. Since $d$ is continuous in the compact $A\times B$, $d$ attains its extremums. That gives you the desired result.
A: I assume that $A$ and $B$ are compact subspaces. As it was was proved here the function $d(\cdot,B):A\to \mathbb{R}_+:a\mapsto\inf\{d(a,b):b\in B\}$ is continuous. But it is defined on the compact space $A$, hence there exist $a_0\in A$ such that
$$
d(a_0,B)=\inf\{d(a,B):a\in B\}=d(A,B)
$$
Similarly the function $d(\{a_0\},\cdot):B\to\mathbb{R}_+:b\mapsto\inf\{d(a_0,b):b\in B\}$ is continuous function on the compact metric space $B$, hence there exist $b_0\in B$ such that 
$$
d(\{a_0\},b_0)=\inf\{d(\{a_0\},b):b\in B\}
$$
What is equivalent to
$$
d(a_0,b_0)=d(a_0,B)=d(A,B)
$$
for some $a_0\in A$ and $b_0\in B$.
