A continuous function and a closed graph Suppose I would like to show that for 2 metric spaces $A,B$, a function $f:A\to B$ and the graph of $f$, $G=\{(a,f(a))\in A\times B|a\in A\}$ that 
$f$ is continuous IFF $G$ is closed (with an additional condition for the $(\Leftarrow)$ direction -- $B$ is compact)
My thoughts are
$(\Rightarrow) a_k\to a \implies f(a_k)\to f(a)$, therefore $(a_k,f(a_k))\to (a,b)\implies (a,b)\in A\times B$.
My doubts are that do I need to say something about the product metric? As far as I know there isn't a unique definition for it. Also this "proof" seems to be too simple -- I think it might be lacking in something.
$(\Leftarrow) $ Suppose $a_k\to a$,  Then since $G$ is compact, given a sequence $(a_k, f(a_k))$, we can find a subsequence $(a_{k_n}, f(a_{k_n}))$ that converges (I am not sure what this law is, I hope I haven't confused the context and that it is really applicable here.) Since the limit is in $G$, therefore $f(a_{k_n})\to f(a)$ for $a_{k_n}\to a$. Therefore $f$ is continuous.
Again, I think there might be holes in my argument, or perhaps even wrong assumptions. 
Please teach me to fix it. Thanks!
 A: I remember doing a similar problem where working by contradiction was easier.
Suppose $a_i$ converges to $a$ but $f(a_i)$ does not converge to $f(a)$. Then there exists an $\epsilon>0$ such that for all $N\in \mathbb{N}$, there exists an $i_N>N$ such that $f(a_{i_N})\notin B(f(a),\epsilon)$.
If $B$ is compact, then there is a subsequence $b_i$ of the $a_{i_N}$ such that $f(b_i)$ converges. Then the sequence $(b_i,f(b_i))$ must converge (since each of its coordinates converge) and since the graph is closed it converges to a point $(b,f(b))$. But then it follows that $b=a$, and so $f(b_i)$ converges to $f(b)=f(a)$, however this is an absurdity because every element of any subsequence of $f(a_{i_N})$ is more than $\epsilon$ from $f(a)$. 
Hence, $f$ preserves convergent sequences, and is continuous. 
A: For the $(\Rightarrow)$ direction, start, as you did, with an arbitrary point $a\in A$ and a sequence $\langle a_k:k\in\Bbb N\rangle$ converging to $a$. Because $B$ is compact, $\langle f(a_k):k\in\Bbb N\rangle$ has a convergent subsequence; say $\langle f(a_{n_k}):k\in\Bbb N\rangle\to b$. Now you want to show that $b=f(a)$ and that the sequence $\langle f(a_k):k\in\Bbb N\rangle$ converges to $b$. We've already used compactness of $B$, so this must be where the assumption that $G$ is closed comes in. Can you take it from here? If not, just ask, and I'll expand this a bit further.
Added: Let $p=\langle a,b\rangle$. You can easily show that that $$\Big\langle\langle a_{n_k},f(a_{n_k})\rangle:k\in\Bbb N\Big\rangle\to p\;.$$ Since the sequence lies in the closed set $G$, we must have $p\in G$, and hence $f(a)=b$. But we're still not quite done, because so far we know only that the subsequence $\langle f(a_{n_k}):k\in\Bbb N\rangle$ converges to $b$, and we need to conclude that $\langle f(a_k):k\in\Bbb N\rangle\to b$. It clearly can't converge to anything else, but it conceivably might not converge. To prove that it does, just show that every subsequence converges to $b$. This does still require a little work.
