What is the use of the disjoint union in the definition of the sheaf of rings on $\mathrm{Spec}(A)$? Hartshorne on pg. 70 defines a sheaf $\mathcal O$ of rings on $\mathrm{Spec}(A)$ to be the set of functions $$s : U \to \bigsqcup_{\mathfrak{p} \in U} A_{\mathfrak{p}},$$
where for each $\mathfrak{p}$, $s(\mathfrak{p})\in A_{\mathfrak{p}}$ and for any $\mathfrak{p}\in U$, there is a neighborhood $V$ of $\mathfrak{p}$ in  $U$ and elements $a, f \in A$ such that for all $\mathfrak{q}$ in $V$, $f \notin \mathfrak{q}$ and $s(\mathfrak{q})=\frac af \in A_{\mathfrak{q}}$.
Question: What is the motivation for including a disjoint union of the localizations of the ring $A$? Why isn't it a simple union?
 A: The idea here is that Hartshorne wants to construct a type of functions.
The first thing to note is that functions on sets themselves can be expressed as a kind of section. In particular, there is a bijective correspondence between


*

*Functions $f : X \to Y$

*Sections $s : X \to X \times Y$ of the first projection map $X \times Y \to X$


The corresponding terms are related by the identity $s(x) = (x, f(x))$.
Since these two notions are in bijective correspondence, practical language tends not to distinguish them. If you write a function where a section was expected, you substitute the corresponding section. And vice versa.
In particular, given such an $h$, what we mean by writing $h(x)$ depends on whether the context demands an element of $X \times Y$ or an element of $Y$.

The given situation is more awkward, since we need a notion of function where the codomain isn't fixed! 
In this situation, its easier to describe the desired notion as sections of the bundle
$$ \bigsqcup_\mathfrak{p} A_\mathfrak{p} \to |\mathrm{Spec}(A)| $$
(where I use $|\cdot|$ to indicate that I'm specifically referring to its set of points) 
The same ambiguity of language mentioned in the previous section apply here. If we're given a thing $h$:


*

*If we're treating $h$ as a section, then what we mean by $h(\mathfrak{p})$ is an element of $\bigsqcup_\mathfrak{p} A_\mathfrak{p}$

*If we're treating $h$ as a function, then what we mean by $h(\mathfrak{p})$ is an element of $A_\mathfrak{p}$


This sort of construction and notation appears more generally in type theory as the notion of a dependent sum.
