Dear Programmers,<div class="gmail_quote"><div class="gmail_quote"><div><br></div><div>Someone just asked me to give my opinion on <a href="http://code.google.com/p/noop/wiki/ProposalForComposition" target="_blank">Noop&#39;s composition proposal</a>. It reminds me a little bit of <a href="http://en.wikipedia.org/wiki/Self_%28programming_language%29" target="_blank">Self</a> which found its way into JavaScript. It also reminds me a little of <a href="http://en.wikipedia.org/wiki/Type_class" target="_blank">Haskell&#39;s type classes</a>. In general, movement away from inheritance is good. The proposal, however, feels a bit like looking for the lost quarter where the light is good, rather than where you lost it. Before considering delegation machinery, let&#39;s consider the <i>value</i> of an interface. How many interfaces are there? One way to see that is just to consider all the sub interfaces of a single interface with n methods on it. Hmmm... that&#39;s 2^n interfaces. That&#39;s a lot. Does that give us any confidence that any one way of carving up functionality via interfaces is going to be sane? Further, in practice, do we see random distribution through this very large space?</div>


<div><br></div><div>What we see over and over again in practice is that the answer to these questions is &#39;no!&#39;. That means that there is <i>something</i> that binds a collection of methods together. What might that something be? One place to look is mathematics. Which maths should we look at? The maths of category has been very fruitful both in explaining existing functional programming techniques and -- perhaps more importantly -- suggesting ways to improve them as well as wholly new techniques. What we find in category theory is that it is natural to collect maps (read functions) together. A good example of such a beast is a monad. A monad -- viewed categorically -- is </div>


<div><ul><li>a map, T, taking types to new types and functions on those types to new functions. Let&#39;s call the universe of types and functions expressible in our model of computation (as proscribed by our programming language), C. Then T : C -&gt; C.</li>


<li>a higher order map, unit. Just like T takes C to C, we can understand a &quot;noop&quot; like map that takes C to C, call it Id. Then unit : Id -&gt; T. We intuitively think about it as putting basic types inside the container T, but it&#39;s really a higher order map.</li>


<li>another higher order map, mult : T^2 -&gt; T. We talk about it as a kind of flattening (and in Scala it&#39;s called flatMap), but it&#39;s a higher order map.</li></ul><div>Now, one is not finished spelling out a monad when giving this collection of maps. One must also show that they satisfy certain constraints.</div>


<div><ul><li>T is functorial, meaning T g f = T(g) T(f)<br></li><li>unit and mult are natural transformations, look up the meaning because unpacking it here would take to long</li><li>mult( mult T ) = mult( T mult )</li>


<li>mult( unit T ) = mult( T unit  )</li></ul><div>This set of constraints must go with the monad. This example provides a little more detail in terms of what binds a group of maps together, and hence of what <i>might</i> replace the notion of interface and <i>explain</i> what we see in practice. Good programmers invariably pick out just a few factorizations of possible interfaces -- from the giant sea of factorizations (read different ways to carve up the functionality). The reason -- i submit -- is because in their minds there are some constraints they know or at least intuit must hold -- but they have no good way at the language level to express those constraints. A really practical language should help the programmer by providing a way express and check the constraints that hold amongst the maps in an interface.</div>


<div><br></div><div>i submit that this idea is not the same as &quot;design by contract&quot;. i am not proposing an Eiffel-like mechanism. Again, taking a functional approach to computation via category theory leads one towards modeling interfaces as categorical &quot;situations&quot; like monads, comonads, distribution laws, etc. This means that a large number of the constraints come down to </div>


<div><ul><li>functoriality</li><li>naturality</li><li>coherence</li></ul><div>Language support for this approach might include <i>keywords for these kinds of assertions</i>. It is a gnarly beast to offer automatic and/or compiler support for checking general constraints. Even this limited family of constraints that i&#39;m proposing can generate some very difficult computations, with very bad complexity. However, for those situations where a general purpose solution to check assertions of functoriality, naturality and coherence are infeasible, one can use these hints to generate tests to probe for possible failures. This idea follows the in the same spirit of replacing proof with proof-checking.<br>

</div><div><br></div><div>Of course, this is not the only way to go. i&#39;ve yet to be convinced that category theory offers a good account of concurrency. Specifically, categorical composition does not line up well with concurrent composition. So, interfaces organized around types for concurrency is also something to consider. In this case, one might find a natural beginning in interfaces in which -- roughly speaking -- the methods constitute the tokens of a formal language the constructors of which are given by the types for concurrency paradigm.<br>

</div>
</div></div></div><div><br></div><div>Best wishes,</div><div><br></div><div>--greg<div><br><br><div class="gmail_quote">On Thu, Sep 17, 2009 at 11:14 AM, Charles F. Munat <span dir="ltr">&lt;<a href="mailto:charles@munat.com" target="_blank">charles@munat.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><a href="http://code.google.com/p/noop/wiki/ProposalForComposition" target="_blank">http://code.google.com/p/noop/wiki/ProposalForComposition</a><br>



</blockquote></div><br><br clear="all"><br></div>-- <br>L.G. Meredith<br>Managing Partner<br>Biosimilarity LLC<br>1219 NW 83rd St <br>Seattle, WA 98117<br><br>+1 206.650.3740<br><br><a href="http://biosimilarity.blogspot.com" target="_blank">http://biosimilarity.blogspot.com</a><br>



</div>
</div><br>
</div>