Heine–Cantor theorem state that if $M$ is compact then the continuous function $f:M\to N$ is uniformly continuous.
Is there a continuous function $f:A\to\Bbb R^n$ such that $f$ is uniformly continuous on $B\subset A$ implies $B$ is compact, i.e. $f$ is uniformly continuous only on compact space?
I thought about using some function $f:\Bbb R\to \Bbb R$, like $x\mapsto x^2$ but I don't know how to approach to this if $B$ is between 2 finites numbers (like $B=(0,1]$)