<p>The common feature of your example is the representation of some (mathematical) object by <em>functions</em>. This is common in functional languages, but not as practical as in mathematics because functions in programs are used extensionally (you cannot inspect their definitions, only observe their actions on arguments), and only with computable operations (you can only observe a finite number of arguments).</p>

<p>In mathematics, you don't bother with such stuff, for example you very often say "if f is analytic, then let's (a_n) be its sequence of coefficients, and...". In a computer language, if you start with a function of type <code>Double -&gt; Integer -&gt; [Double]</code>, it will be painful to convert it to a representation where you can easily recover the coefficients. In programming languages, function <em>really</em> are black boxes.</p>

<p>For this reason, programmers often try to use explicit data representations instead of function black boxes. You can easily obtain a function from a data representation (its a kind of evaluation or interpretation), while the other way around can be more difficult, less efficient, etc. See Conal Elliott's <a href="http://conal.net/blog/posts/everything-is-a-function-in-haskell/" rel="noreferrer">“Everything is a function” in Haskell?</a>.</p>

<p>Functions are however still used in cases where we really want extensional objects, that can only be observed instead of inspected. For each possible observation on the object you want to define, you give a function that realize this observation. In your example, you only have one function because you only have one observation. This is the core idea of Object Oriented Programming as defined by William Cook in his <a href="http://lambda-the-ultimate.org/node/3668" rel="noreferrer">On Understanding Data Abstraction, Revisited</a> paper.</p>

<p>I think the reason why you relate this to the term "duality" (a term that is, in the Haskell intelligentsia, rather related to category-theoretic concepts) is that the shift from an object to some particular form of observation of it is sometimes called duality in maths, and has the effect of adding functions everywhere. For example, there is the classical example of the dual of a vector space, and in particular the bidual construction which is really a conversion from a vector to its observations by linear functions : you switch from <code>V</code> to <code>(V -&gt; K) -&gt; K</code>, for <code>K</code> the field underlying your vector space.</p>

<p>(Would one think of continuations reading my last example ? Of course those are related, as this representation of continuations is really an "observation" of concrete evaluation contexts, represented by their action on values.)</p>

<p>Your representation of probability measures is actually used to define probability measure monads in functional languages. There are different ways to define probability monads. See for example <a href="http://www.cs.tufts.edu/~nr/pubs/pmonad-abstract.html" rel="noreferrer">http://www.cs.tufts.edu/~nr/pubs/pmonad-abstract.html</a> by Norman Ramsey and Avi Pfeffer. Most real-world implementation of probability DSL however use a more concrete representation such as a <code>[(prob,event)]</code> list of pair (Haskell <a href="http://www.haskell.org/haskellwiki/Probabilistic_Functional_Programming" rel="noreferrer">probability</a> library and OCaml <a href="http://okmij.org/ftp/kakuritu/" rel="noreferrer">HANSEI</a>).</p>

<p>Finally, for an example of representation of real number as functions, see Russel O'Connor's <a href="http://arxiv.org/abs/cs.NA/0605058" rel="noreferrer">A Monadic, Functional Implementation of Real Numbers</a>. Numerous representation of "computable" numbers exist and have different merits, and most of them are based on sequences and may therefore be represented as <code>Integer -&gt; ...</code> functions.</p>
Duality approaches in functional programming
<p>I'd like to know what kind of <strong>real life</strong> problems can be tackled by "duality methods" in functional programming. More precisely, I'd like to know whether someone did actually use a duality method like the ones I present below, or whether there are other interesting examples. I'd be particularly interested in <strong>existing implementations</strong>, probably in Haskell.</p>

<p><em>[Since the majority of people which will be interested in this question likely know Haskell, let me please add the Haskell tag, even if the question is quite language independent]</em></p>

<p>Let me explain what I mean by duality (by lack of a better name) through a few examples. The first one is the <strong>real numbers</strong>. Assume the existence of a <code>Integer</code> and a <code>Rational</code> type, and define a real number as a function (pardon my Haskell, I'm no hardcore haskeller)</p>

<pre><code>type Real = Integer -&gt; Rational
</code></pre>

<p>such that whenever <code>x :: Real</code> denotes the real number x, <code>x n</code> yields a rational number which is within <code>2^(-n)</code> of x.</p>

<p>Now one can do</p>

<pre><code>(+) :: Real -&gt; Real -&gt; Real
(+) x y n = (x $ n + 1) + (y $ n + 1)
</code></pre>

<p>or likewise for other arithmetic operations. Given a continuous real function f, one can also compute <code>f x</code> as soon as one can compute a <a href="http://en.wikipedia.org/wiki/Modulus_of_continuity" rel="nofollow noreferrer">modulus of continuity</a> for <code>f</code>.</p>

<p>This has the advantage that one can write natural looking code, and at the end, get a result at the desired level of precision automatically. However, it is no longer possible to compare real numbers for equality. The only kind of comparison possible between <code>x</code> and <code>y</code>  is <code>x &lt; y + eps</code>.</p>

<p>Another example of duality is <a href="https://stackoverflow.com/questions/395981">this question on <strong>probability measures</strong></a>, which triggered the present question in my head. Let us write</p>

<pre><code>type Measure a = (a -&gt; Double) -&gt; Double
</code></pre>

<p>and define measures as integration procedures against functions. In the linked question, I show how natural it is in this framework to express concepts like convolution or pushforward which are much more difficult (computationally, but also theoretically) to define at the level of probability <em>densities</em>.</p>

<p>It allows one to compose building blocks from probability theory, and in principle allows one to build complex Monte Carlo procedures, and even allows one to work with explicit probability densities (at the expense of numerical integration). I'd be especially interested in any attempt at a real world library on this topic.</p>

<p>Another example that I have in mind, but did not quite formalize yet is the notion of <strong>vector fields</strong> (from differential geometry), that one can express as <em>differentiation operators</em>. For this, one needs a suitable type of "smooth real valued functions", and then a vector field is like this:</p>

<pre><code>type VectorField = SmoothFunction -&gt; SmoothFunction
</code></pre>

<p>such that <code>v (f * g) = f * (v g) + g * (v f)</code>.</p>

<p>Of course, describing a sheaf of regular functions in say Haskell should not be easy. But by doing that, we could express all the stuff from differential geometry in a totally coordinate independant way, and plug coordinates at the very end.</p>

<p>There are other examples, eg. <strong>Taylor series</strong> have been discussed in Sigfpe's blog (I can't find this particular post though), where an analytic function is the following type:</p>

<pre><code>type AnalyticFunction = Double -&gt; Integer -&gt; [Double]
</code></pre>

<p>and where <code>f x n</code> returns the <code>n</code> first partial sums of the Taylor expansion of <code>f</code> around <code>x</code>. This allows us to seamlessly write all kind of arithmetic on analytic functions, including stuff like <code>f / g</code> where <code>f</code> and <code>g</code> both can vanish at a point (along with some of their derivatives), or even <code>f^(-1)</code> (provided <code>f'</code> does not vanish). At the end, only the necessary terms of the intermediate series are computed to yield the value of a given expression.</p>