What are the minimum constraints on the domain and range of a function in order for it to be differentiable?

For example if $S$ is a set with two elements $a$ and $b$, then you could define:

$f : \mathbb{R} \to S, s.t. f(x) = a, \forall x \in \mathbb{R}$

Intuitively, since f is a constant function, it seems it ought to be be differentiable, but is the constant value of $f'$ going to be $a$ or $b$? Obviously some structure (e.g. Group or Semigroup) is needed on $S$ in order to pick one.

-
The derivative is most naturally generalized to the Frechet derivative, which has the same definition as the good old $\mathbb{R}\rightarrow \mathbb{R}$ derivative but works on normed vector spaces. I don't call this an answer, though, since it can certainly be extended further. – Kevin Carlson Sep 26 '12 at 11:38
@MichaelJoyce Zero is not necessarily in the range of the function. But if something zero-like is required then that might be part of the constraint. E.g. as Kevin said, the domain might be required to be a Vector space, so there would be a multiplicative identity that can be labelled as 0. (Also, the domain of my example is $R$, not the two-element set.) – Peter Hall Sep 26 '12 at 12:47
Sorry I misread the question as suggesting that you were studying $f : \{a,b\} \rightarrow \{a\}$. I still don't think it makes sense to say that the constant function has derivative anything other than $0$, so I think you need some kind of structure on $S$ that includes a $0$. – Michael Joyce Sep 27 '12 at 5:14
As @Qiaochu hints, the values of a derivative should not be expected to lie in the range of a differentiable function. – Lubin Sep 29 '12 at 19:14

As Qiaochu points out, you should look up differentiable manifolds. There the derivatives are not functions to the manifold $M$ itself but rather into the tangent space bundel, which is a vector space "attached" to each point of $M$. The tangent space at $p\in M$ can be constructed as equivalence classes of curves through $p$, where we declare those curves equivalent which we wish to be in the following sense.
If $\gamma\colon \mathbb R\to M$ is any curve with $\gamma(0)=p$, the derivative at $t=0$ as element in the tangent space $T_p$ should describe the "speed" at which we pass through $p$. If we replace $\gamma$ with $t\mapsto\gamma(v t)$, we therefore wish the "speed" to be multiplied by $v$. Hence at least multiplication with real numbers should be possible in $T_p$. This does not make $T_p$ a vector space yet because we lack addition. Also, we have not made up our mind yet, which curves to call differentiable in the first place. In the end, the most natural setting to have a sufficiently rich theory of differentiability is indeed that of differentiable manifolds, i.e. spaces that "look like" copies of $\mathbb R^n$ smoothly glued together.