Abstracted Metric and Measure Spaces As I am just beginning to study general topology and metric spaces in more and more detail, it seems to me that the metric space topology is entirely determined by the properties of $\Bbb R$, since the metric goes to $\Bbb R$. If we could define a "distance" function to a more abstract space than $\Bbb R$ (call it $D$), I feel this would limit our constraints on the type of topologies we see.
$$\tilde d:X \times X \to D$$
What properties would we need to require $D$ have?
Does anybody know of any examples of this being done? Also, does anybody know, if this can be done reasonably, what types of topologies are we able to induce from this?
Similarly, if we could lessen the constraint that some measure $\mu$ must send subsets to $\Bbb R^{\ge 0} \cup \{ \infty \}$ and instead can "measure" subsets in a more abstract way, what would be a motivation and/or intuition for such a "measure", $\tilde \mu$?
Any other related response to this subject area will receive an up-vote. Thanks
 A: The problem is that you wouldn't really be able to generalize the properties that a metric has, so it wouldn't really be at all like a "distance".  In particular, without the algebraic structure of $\mathbb{R}$ the triangle inequality would not make sense, and without the order-theoretic structure, non-negativity wouldn't make sense either.  Symmetry would continue to be well-defined for any map $d:X\times X\rightarrow D$, though, and positive definiteness could be recovered by picking some element of $D$ and using that in lieu of $0$.  Thus, we'd have to remove some notion of "distance" if we want to generalize it.
One simple generalization that bypasses this is by just enlarging $\mathbb{R}$.  You can replace $\mathbb{R}$ with $[0,\infty]$, allowing for infinite distances; these are called either extended metrics or $\infty$-metrics. Ultimately, this ends up being reducible to metrics though, in the sense that every extended metric can be transformed into a metric with the topology staying intact.
There are also ways of weakening the properties of a metric to include more examples. So that I can easily reference them, I recall the properties of a metric $d:X\times X\rightarrow \mathbb{R}$:


*

*Non-negativity: $d(x,y)\geq 0$ for every $x,y\in X$.

*Identity of Indiscernables (or Positive Definiteness): $d(x,y)=0$ if and only if $x=y$ for every $x,y\in X$.

*Symmetry: $d(x,y)=d(y,x)$ for every $x,y\in X$.

*Triangle Inequality: $d(x,y)\leq d(x,z)+d(z,y)$ for every $x,y,z\in X$.


Now on to our generalizations:


*

*Then a pseudometric is a map $d:X\times X\rightarrow \mathbb{R}$ satisfying 1, 3, 4, and $d(x,x)=0$.  An example of a pseudometric that is not a metric uses the space $\mathcal{F}(X)$ of functions $f:X\rightarrow \mathbb{R}$ where for a fixed point $x_0\in X$ we define $d(f,g)=|f(x_0)-g(x_0)|$. Since the property 2 doesn't really depend on the structure of $\mathbb{R}$, weakening it doesn't really offer clues into generalization, especially considering the order-theoretic and algebraic structures of $\mathbb{R}$ are still being employed.

*A quasimetric is a map $d:X\times X\rightarrow \mathbb{R}$ satisfying 1, 2, and 4.  A quasimetric on $\mathbb{R}$ that is not a metric is given by $d(x,y)=\begin{cases} x-y & \text{if $x\geq y$} \\ 1 & \text{otherwise.} \end{cases}$; this generates the lower-limit topology $\mathbb{R}_\ell$.  Since symmetry is really never an impediment for choosing some set $D$ to fill in for $\mathbb{R}$, this doesn't really offer any clues into generalization.

*A semimetric is a map $d:X\times X\rightarrow \mathbb{R}$ satisfying 1,2, and 3.  Thus, the algebraic structure of $\mathbb{R}$ is no longer considered, opening some venue for generalizing the notion to any totally-ordered set with a distinguished point to fill in for $0$.  
Central to all of these is the order, which is used to define the open balls that make up the base used to define the topology.  Thus, you could potentially replace $\mathbb{R}$ with any ordered set and pick something like a semimetric to get something "distance-like".  One way of specifying this a bit more involves replacing $\mathbb{R}$ with a totally-ordered set and replacing the triangle inequality with the order-theoretic variant of the ultrametric property, i.e. $d(x,y)\leq \max\{d(x,z),d(z,y)\}$.
In a different direction is the notion of uniform spaces, which instead of capturing the idea of distance instead capture the idea of 'closeness'.  This is typically done using "entourages", a collection of subsets of $X\times X$ that capture the notion of "at least as close as" some fixed amount, so that a relation of $x$ being "closer" to $y$ than $z$ is can be defined by saying that $(x,y)$ lies in an entourage that is a proper subset of an entourage that $(z,y)$ lies in.  However, it is possible to define, for certain uniform spaces, using a pseudometric.
A: The most naive generalization of a metric space would be to let the distance function take values in some $\mathbb{R}^n$, ordered lexicographically.  Such a "rank $n$ metric space" would share many properties with traditional metric spaces, but it would lack the archimedean property that $X = \bigcup_{n=1,2,\ldots} \{y\in X \mid d(x,y)\leq n\}$ for any $x\in X$.
But it is a theorem that any totally ordered abelian group with the archimedean property is a subgroup of $\mathbb{R}$, so this generalization amounts to discarding this property.  This is potentially useful—for example, one can collect the points of $\mathbb{R}^n$, and all its tangent vectors, into a single rank $2$ metric space—but to the best of my knowledge, not much has been written about this.
(However, higher-rank valuations on rings have been studied extensively, and in principle these should give you higher-rank metric spaces.)

Taken very much to the extreme, the generalization of a metric space is a category $\mathcal{C}$, enriched over a symmetric monoidal category $\mathcal{M}$.  We recover the definition of metric spaces when $\mathcal{M}$ is the monoidal category whose objects are the non-negative real numbers, whose morphisms are inequalities $a\leq b$, and whose monoidal product is $a\otimes b = a+b$.
Note that the existence of a composition morphism, $\operatorname{Hom}(x,y) \otimes \operatorname{Hom}(y,z) \to \operatorname{Hom}(x,z)$, is exactly the triangle inequality!
