<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Existential Type</title>
	<atom:link href="http://existentialtype.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://existentialtype.wordpress.com</link>
	<description>Abstract types are existential types.</description>
	<lastBuildDate>Mon, 18 Feb 2013 17:02:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='existentialtype.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://0.gravatar.com/blavatar/4192ff5d4a07fc7f4fa2a2ff285af64e?s=96&#038;d=http%3A%2F%2Fs2.wp.com%2Fi%2Fbuttonw-com.png</url>
		<title>Existential Type</title>
		<link>http://existentialtype.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://existentialtype.wordpress.com/osd.xml" title="Existential Type" />
	<atom:link rel='hub' href='http://existentialtype.wordpress.com/?pushpress=hub'/>
		<item>
		<title>More Is Not Always Better</title>
		<link>http://existentialtype.wordpress.com/2013/01/28/more-is-not-always-better/</link>
		<comments>http://existentialtype.wordpress.com/2013/01/28/more-is-not-always-better/#comments</comments>
		<pubDate>Mon, 28 Jan 2013 23:58:45 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[semantics]]></category>
		<category><![CDATA[type theory]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=797</guid>
		<description><![CDATA[In a previous post I discussed the status of Church&#8217;s Law in type theory, showing that it fails to hold internally to extensional type theory, even though one may see externally that the definable numeric functions in ETT are λ-definable, and hence Turing computable.  The distinction between internal and external is quite important in logic, mainly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=797&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In a <a title="Church’s Law" href="http://existentialtype.wordpress.com/2012/08/09/churchs-law/">previous post </a>I discussed the status of Church&#8217;s Law in type theory, showing that it fails to hold <em>internally</em> to extensional type theory, even though one may see <em>externally</em> that the definable numeric functions in ETT are λ-definable, and hence Turing computable.  The distinction between internal and external is quite important in logic, mainly because a logical formalism may be unable to express precisely an externally meaningful concept.  The classical example is the Löwenheim-Skolem Theorem of first-order logic, which says that any theory with an infinite model has a countable model.  In particular the theory of sets has a countable model, which would seem to imply that the set of real numbers, for example, is countable.  But internally one can prove that the reals are uncountable (Cantor&#8217;s proof is readily expressed in the theory), which seems to be a paradox of some kind.  But no, all it says is that the function witnessing the countability of the term model cannot be expressed internally, and hence there is no contradiction at all.</p>
<p>A similar situation obtains with Church&#8217;s Law.  One may observe empirically, so to say, that Church&#8217;s Law holds externally<em> </em>of ETT, but this fact cannot be internalized.  There is a function given by Church&#8217;s Law that &#8220;decompiles&#8221; any (extensional) function of type <em>N→N</em> by providing the index for a Turing machine that computes it.  But this function cannot be definable internally to extensional type theory, because it may be used to obtain a decision procedure for halting of Turing machines, which is internally refutable by formalizing the standard undecidability proof.  In both of these examples it is the <em>undefinability</em> of a function that is important to the expressive power of a formalism, contrary to naïve analyses that would suggest that, when it comes to definability of functions, the more the merrier.  This is a general phenomenon in type theory.  The power of type theory arises from its <em>strictures</em>, not its <em>affordances</em>, in direct opposition to the ever-popular language design principle &#8220;first-class <em>x</em>&#8221; for all imaginable values of <em>x</em>.</p>
<p>Another perspective on the same issue is provided by Martin-Löf&#8217;s <em>meaning explanation</em> of type theory, which is closely related to the theory of <em>realizability</em> for constructive logic.  The high-level idea is that a justification for type theory may be obtained by <em>starting</em> with an untyped concept of computability (<em>i.e.,</em> a programming language given by an operational semantics for closed terms), and then giving the meaning of the judgments of type theory in terms of such computations.  So, for example, the judgment <em>A type</em>, where <em>A</em> is a closed expression means that <i>A</i> evaluates to a <em>canonical</em> type, where the canonical types include, say, <em>Nat,</em> and all terms of the form <em>A&#8217;→A&#8221;</em>, where <em>A&#8217;</em> and <em>A&#8221;</em> are types.  Similarly, if <em>A</em> is a type, the judgment <em>a:A </em>means that <em>A</em> evaluates to a canonical type <em>A&#8217;</em> and that <em>a</em> evaluates to a canonical term <em>a&#8217;</em> such that <em>a&#8217;</em> is a canonical element of <em>A&#8217;</em>, where, say, any numeral for a natural number is a canonical member of <em>Nat.</em>  To give the canonical members of the function type <em>A&#8217;→A&#8221;</em> requires the further notion of <em>equality</em> of elements of a type, <em>a=b:A</em>, which all functions are required to respect.  A meaning explanation of this sort was suggested by Martin-Löf in his landmark paper <a title="Constructive Mathematics and Computer Programming" href="http://rsta.royalsocietypublishing.org/content/312/1522/501.short" target="_blank"><em>Constructive Mathematics and Computer Programming</em></a>, and is used as the basis for the <a title="NuPRL Project" href="http://nuprl.org" target="_blank">NuPRL type theory</a>, which extends that account in a number of interesting directions, including inductive and coinductive types, subset and quotient types, and partial types.</p>
<p>The relation to realizability emerges from applying the meaning explanation of types to the semantics of propositions given by the propositions-as-types principle (which, as I&#8217;ve <a title="Extensionality, Intensionality, and Brouwer’s Dictum" href="http://existentialtype.wordpress.com/2012/08/11/extensionality-intensionality-and-brouwers-dictum/" target="_blank">previously argued</a>, should <i>not</i> be called &#8220;the Curry-Howard isomorphism&#8221;).  According to this view a proposition <em>P</em> is identified with a type, the type of its proofs, and we say that <em>P true</em> iff <em>P </em>evaluates to a canonical proposition that has a canonical member.  In particular, for implication we say that <em>P→Q</em> <em>true</em> if and only if <em>P true</em> implies <em>Q true</em> (and, in addition, the proof respects equality, a condition that I will suppress here for the sake of simplicity).  More explicitly, the implication is true exactly when the truth of the antecedent implies the truth of the consequent, which is to say that there is a constructive transformation of proofs of <em>P</em> into proofs of <em>Q</em>.</p>
<p>In <em>recursive realizability</em> one accepts Church&#8217;s Law and demands that the constructive transformation be given by the index of a Turing machine (<em>i.e.</em>, by a program written in a fixed programming language).  This means, in particular, that if <em>P</em> expresses, say, the decidability of the halting problem, for which there is <em>no recursive realizer</em>, then the implication <em>P→Q</em> is vacuously true!  By taking <em>Q</em> to be falsehood, we obtain a realizer for the statement that the halting problem is undecidable.  More generally, any statement that is not realized is automatically <em>false </em> in the recursive realizability interpretation, precisely because the realizers are identified with Turing machine indices.  Pressing a bit further, there are statements, such as the statement that every Turing machine either halts or diverges on its own input, that are <em>true</em> in classical logic, yet have no recursive realizer, and hence are <em>false</em> in the realizability interpretation.</p>
<p>In contrast in the meaning explanation for NuPRL <em>Church&#8217;s Law is not assumed</em>.  Although one may show that there is no <em>Turing machine</em> to decide halting for Turing machines, it is impossible to show that there is no <em>constructive transformation</em> that may do so.  For example, an oracle machine would be able to make the required decision.  This is entirely compatible with intuitionistic principles, because although intuitionism does not <em>affirm</em> LEM, neither does it <em>deny</em> it.  This point is often missed in some accounts, leading to endless confusions.  Intuitionistic logic, properly conceived, is <em>compatible</em> with classical logic in that classical logic may be seen as an idealization of intuitionistic logic in which we heuristically postulate that all propositions are decidable (all instances of LEM hold).</p>
<p>The crucial point distinguishing the meaning explanation from recursive realizability is precisely the <em>refusal</em> to accept Church&#8217;s Law, a kind of comprehension principle for functions as discussed earlier.  This refusal is often called <em>computational open-endedness</em> because it amounts to avoiding a commitment to the blasphemy of limiting God&#8217;s programming language to Turing machines (using an apt metaphor of Andrej Bauer&#8217;s).  Rather, we piously accept that richer notions of computation are possible, and avoid commitment to a &#8221;final theory&#8221; of computation in which Church&#8217;s Law is postulated outright.  By avoiding the witnessing function provided by Church&#8217;s Law we <em>gain</em> expressive power, rather than losing it, resulting in an elegant theory of constructive mathematics that enriches, rather than diminishes, classical mathematics.    In short, contrary to &#8220;common sense&#8221; (<em>i.e.,</em> uninformed supposition), <em>more is not always better</em>.</p>
<p><em>Update</em>: corrected minor technical error and some typographical errors.</p>
<p><em>Update</em>: clarified point about incompatibility of recursive realizability with classical logic.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/research/'>Research</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/semantics/'>semantics</a>, <a href='http://existentialtype.wordpress.com/tag/type-theory/'>type theory</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/797/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/797/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=797&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2013/01/28/more-is-not-always-better/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		<georss:point>40.441674 -79.947818</georss:point>
		<geo:lat>40.441674</geo:lat>
		<geo:long>-79.947818</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Exceptions are shared secrets</title>
		<link>http://existentialtype.wordpress.com/2012/12/03/exceptions-are-shared-secrets/</link>
		<comments>http://existentialtype.wordpress.com/2012/12/03/exceptions-are-shared-secrets/#comments</comments>
		<pubDate>Tue, 04 Dec 2012 03:22:25 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[PFPL]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=782</guid>
		<description><![CDATA[It&#8217;s quite obvious to me that the treatment of exceptions in Haskell is wrong. Setting aside the example I gave before of an outright unsoundness, exceptions in Haskell are nevertheless done improperly, even if they happen to be sound. One reason is that the current formulation is not stable under seemingly mild extensions to Haskell [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=782&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s quite obvious to me that the treatment of exceptions in Haskell is wrong. Setting aside <a title="Haskell Is Exceptionally Unsafe" href="http://existentialtype.wordpress.com/2012/08/14/haskell-is-exceptionally-unsafe/">the example I gave before</a> of an outright unsoundness, exceptions in Haskell are nevertheless done improperly, even if they happen to be sound. One reason is that the current formulation is not stable under seemingly mild extensions to Haskell that one might well want to consider, notably any form of parameterized module or any form of shadowing of exception declarations. For me this is enough to declare the whole thing wrong, but as it happens Haskell is too feeble to allow full counterexamples to be formulated, so one may still claim that what is there now is ok &#8230; for now.</p>
<p>But I wish to argue that Haskell exceptions are nevertheless poorly designed, because it misses the crucial point that <em>e</em><em>xception values are shared secrets</em>. Let us distinguish two parties, the <em>raiser</em> of the exception, and the <em>handler</em> of it. The fundamental idea of exceptions is to transfer a value from the raiser to the handler <em>without the possibility of interception by another party</em>. While the language of secrecy seems appropriately evocative, I hasten to add that I am not here concerned with &#8220;attackers&#8221; or suchlike, but merely with the difficulties of ensuring <em>modular composition</em> of programs from components. In such a setting the &#8220;attacker&#8221; is yourself, who is not malicious, but who is fallible.</p>
<p>By raising an exception the raiser is &#8220;contacting&#8221; a handler with a message. The raiser wishes to limit which components of a program may intercept that message. More precisely, the raiser wishes to ensure that only certain previously agreed-upon components may handle that exception, perhaps only one. This property should remain stable under extension to the program or composition with any other component. It should not be possible for an innocent third party to accidentally intercept a message that was not intended for it.</p>
<p>Achieving this requires a <em>secrecy mechanism</em> that allows the raiser and the handler(s) to agree upon their cooperation. This is accomplished by <em>dynamic classification</em>, exactly as it is done properly in Standard ML (but not O&#8217;Caml). The idea is that the raiser has access to a <em>dynamically generated</em> constructor for exception values, and any handler has access to the corresponding dynamically generated <em>matcher</em> for exception values. This means that the handler, and only the handler, can decode the message sent by the raiser; no other party can do anything with it other than pass it along unexamined. It is &#8220;perfectly encrypted&#8221; and cannot be deciphered by any unintended component.</p>
<p>The usual exception <em>mechanisms</em>, as distinct from exception <em>values</em>, allow for &#8220;wild-card handlers&#8221;, which means that an exception can be intercepted by a third party. This means that the raiser cannot ensure that the handler actually receives the message, but it can ensure, using dynamic classification, that <em>only a legitimate handler may decipher it.</em> Decades of experience with Standard ML shows that this is a very useful thing indeed, and has application far beyond just the simple example considered here. For full details, see my forthcoming book, for a full discussion of dynamic classification and its role for ensuring integrity and confidentiality in a program. Dynamic classification is not just for &#8220;security&#8221;, but is rather a good tool for everyday programming.</p>
<p>So why does Haskell not do it this way?  Well, I&#8217;m not the one to answer that question, but my guess is that doing so conflicts with the monadic separation of effects.  To do exceptions properly requires dynamic allocation, and this would force code that is otherwise functional into the IO monad.  Alternatively, one would have to use unsafePerformIO&#8212;as in ezyang&#8217;s implementation&#8212;to &#8220;hide&#8221; the effects of exception allocation.  But this would then be further evidence that the strict monadic separation of effects is untenable.</p>
<p><em>Update</em>: Reworked last paragraph to clarify the point I am making; the previous formulation appears to have invited misinterpretation.</p>
<p><em>Update</em>: This account of exceptions also makes clear why the perennial suggestion to put exception-raising information into types makes no sense to me.  I will write more about this in a future post, but meanwhile contemplate that a computation may raise an exception that is not even in principle nameable in the type.  That is, it is not conservativity that&#8217;s at issue, it&#8217;s the very idea.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/programming/'>Programming</a>, <a href='http://existentialtype.wordpress.com/category/research/'>Research</a>, <a href='http://existentialtype.wordpress.com/category/teaching-2/'>Teaching</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/exceptions/'>exceptions</a>, <a href='http://existentialtype.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://existentialtype.wordpress.com/tag/pfpl/'>PFPL</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/782/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/782/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=782&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/12/03/exceptions-are-shared-secrets/feed/</wfw:commentRss>
		<slash:comments>35</slash:comments>
		<georss:point>40.436644 -79.927319</georss:point>
		<geo:lat>40.436644</geo:lat>
		<geo:long>-79.927319</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>PFPL is out!</title>
		<link>http://existentialtype.wordpress.com/2012/12/03/pfpl-is-out/</link>
		<comments>http://existentialtype.wordpress.com/2012/12/03/pfpl-is-out/#comments</comments>
		<pubDate>Tue, 04 Dec 2012 02:42:33 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Teaching]]></category>
		<category><![CDATA[PFPL]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=780</guid>
		<description><![CDATA[Practical Foundations for Programming Languages, published by Cambridge University Press, is now available in print! It can be ordered from the usual sources, and maybe some unusual ones as well. If you order directly from Cambridge using this link, you will get a 20% discount on the cover price (pass it on). Since going to [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=780&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p><em>Practical Foundations for Programming Languages,</em> published by Cambridge University Press, is now available in print!  It can be ordered from the usual sources, and maybe some unusual ones as well.  If you order directly from Cambridge using <a title="Order Practical Foundations for Programming Languages" href="http://www.cambridge.org/us/knowledge/discountpromotion/?site_locale=en_US&amp;code=L2PFPL" target="_blank">this link,</a> you will get a 20% discount on the cover price (pass it on).</p>
<p>Since going to press I have, inevitably, been informed of some (so far minor) errors that are corrected in the <a title="Practical Foundations for Programming Languages" href="http://www.cs.cmu.edu/~rwh/plbook/book.pdf" target="_blank">online edition</a>.  These corrections will make their way into the second printing.  If you see something fishy-looking, compare it with the online edition first to see whether I may have already corrected the mistake.  Otherwise, send your comments to <a href="mailto:rwh@cs.cmu.edu" target="_blank">me</a>.</p>
<p>By the way, the cover artwork is by <a title="Scott Draves" href="http://scottdraves.com" target="_blank">Scott Draves</a>, a former student in my group, who is now a professional artist as well as a researcher at Google in NYC.  Thanks, Scott!</p>
<p><em>Update</em>: The very first author&#8217;s copy hit my desk today!</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/programming/'>Programming</a>, <a href='http://existentialtype.wordpress.com/category/research/'>Research</a>, <a href='http://existentialtype.wordpress.com/category/teaching-2/'>Teaching</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/pfpl/'>PFPL</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/780/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/780/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=780&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/12/03/pfpl-is-out/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		<georss:point>40.436644 -79.927319</georss:point>
		<geo:lat>40.436644</geo:lat>
		<geo:long>-79.927319</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Univalent Foundations at IAS</title>
		<link>http://existentialtype.wordpress.com/2012/12/03/univalent-foundations-program/</link>
		<comments>http://existentialtype.wordpress.com/2012/12/03/univalent-foundations-program/#comments</comments>
		<pubDate>Mon, 03 Dec 2012 05:06:03 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[homotopy theory]]></category>
		<category><![CDATA[type theory]]></category>
		<category><![CDATA[univalence]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=771</guid>
		<description><![CDATA[As many of you may know, the Institute for Advanced Study is sponsoring a year-long program, called &#8220;Univalent Foundations for Mathematics&#8221; (UF), which is developing the theory and applications of Homotopy Type Theory (HTT).  The UF program is organized by Steve Awodey (CMU), Thierry Coquand (Chalmers), and Vladimir Voevodsky (IAS).  About two dozen people are in residence [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=771&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>As many of you may know, the <a title="Institute for Advanced Study" href="http://ias.edu" target="_blank">Institute for Advanced Study</a> is sponsoring a year-long program, called &#8220;<a title="Univalent Foundations" href="http://www.math.ias.edu/sp/univalent" target="_blank">Univalent Foundations for Mathematics</a>&#8221; (UF), which is developing the theory and applications of <a title="Higher-Dimensional Type Theory" href="http://existentialtype.wordpress.com/2011/05/30/higher-dimensional-type-theory/" target="_blank">Homotopy Type Theory</a> (HTT).  The UF program is organized by <a title="Steve Awodey" href="http://www.andrew.cmu.edu/~awodey" target="_blank">Steve Awodey</a> (CMU), <a title="Thierry Coquand" href="http://www.cse.chalmers.se/~coquand" target="_blank">Thierry Coquand</a> (Chalmers), and <a href="http://www.math.ias.edu/~vladimir" target="_blank">Vladimir Voevodsky</a> (IAS).  About two dozen people are in residence at the Institute to participate in the program, including Peter Aczel, Andrej Bauer, Peter Dybjer, Dan Licata, Per Martin-Löf, Peter Lumsdaine, Mike Shulman, and many others.  I have been shuttling back and forth between the Institute and Carnegie Mellon, and will continue to do so next semester.</p>
<p>The excitement surrounding the program is palpable.  We all have the sense that we are doing something <em>important</em> that will change the world.  A typical day consists of one or two lectures of one or two hours, with the rest of the day typically spent in smaller groups or individuals working at the blackboard.  There are many strands of work going on simultaneously, including fundamental type theory, developing proof assistants, and formulating a body of informal type theory.  As visitors come and go we have lectures on many topics related to HTT and UF, and there is constant discussion going on over lunch, tea, and dinner each day.  While there I work each day to the point of exhaustion, eager to pursue the many ideas that are floating around.</p>
<p>So, why is homotopy type theory so exciting?  For me, and I think for many of us, it is the most exciting development in type theory since its inception.  It brings together two seemingly disparate topics, algebraic topology and type theory, and provides a gorgeous framework in which to develop both mathematics and computer science.  Many people have asked me why it&#8217;s so important.  My best answer is that it&#8217;s too beautiful to be ignored, and such a beautiful concept bmust be good for something!  We&#8217;ll be at this for years, but it&#8217;s too soon to say yet where the best applications of HTT will arise.  But I am sure in my bones that it&#8217;s as important as type theory itself.</p>
<p>Homotopy type theory is based on two closely related concepts:</p>
<ol>
<li><em>Constructivity</em>.  Proofs of propositions are mathematical objects classified by their types.</li>
<li><em>Homotopy.</em>  Paths between objects of a type are proofs of their interchangeability in all contexts.  Paths in a type form a type whose paths are homotopies (deformations of paths).</li>
</ol>
<p>Homotopy type theory is organized so that maps and families <em>respect homotopy</em>, which, under the identification of paths with equality proofs, means that they respect equality.  The force of this organization arises from axioms that specify what are the paths within a type.   There are two major sources of non-trivial paths within a type, the <em>univalence axiom</em>, and <em>higher inductive types</em>.</p>
<p>The univalence axiom specifies that there is an equivalence between equivalences and equalities of the objects of a universe.  Unravelling a bit, this means that for any two types inhabiting a universe, evidence for their equivalence (a pair of maps that are inverse up to higher homotopy, called <em>weak equivalence</em>) is evidence for their equality.  Put another way, weak equivalences are paths in the universe.  So, for example, a bijection between two elements of the universe <img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7BSet%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;textsf{Set}' title='&#92;textsf{Set}' class='latex' /> of sets constitutes a proof of the <em>equality</em> (universal interchangeability) of the two sets.</p>
<p>Higher inductive types allow one to define types by specifying their elements, any paths between their elements, any paths between those paths, and so on to any level, or <em>dimension</em>.  For example, the interval, <img src='http://s0.wp.com/latex.php?latex=I&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='I' title='I' class='latex' />, has as elements the endpoints <img src='http://s0.wp.com/latex.php?latex=0%2C+1+%3A+I&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='0, 1 : I' title='0, 1 : I' class='latex' />, and a path <img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7Bseg%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;textsf{seg}' title='&#92;textsf{seg}' class='latex' /> between <img src='http://s0.wp.com/latex.php?latex=0&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='0' title='0' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='1' title='1' class='latex' /> within <img src='http://s0.wp.com/latex.php?latex=I&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='I' title='I' class='latex' />.  The circle, <img src='http://s0.wp.com/latex.php?latex=S%5E1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='S^1' title='S^1' class='latex' /> has an element <img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7Bbase%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;textsf{base}' title='&#92;textsf{base}' class='latex' /> and a path <img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7Bloop%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;textsf{loop}' title='&#92;textsf{loop}' class='latex' /> from <img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7Bbase%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;textsf{base}' title='&#92;textsf{base}' class='latex' /> to itself within <img src='http://s0.wp.com/latex.php?latex=S%5E1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='S^1' title='S^1' class='latex' />.</p>
<p>Respect for homotopy means that, for example, a family <img src='http://s0.wp.com/latex.php?latex=F&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='F' title='F' class='latex' /> of types indexed by the type <img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7BSet%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;textsf{Set}' title='&#92;textsf{Set}' class='latex' /> must be such that if <img src='http://s0.wp.com/latex.php?latex=A&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A' title='A' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='B' title='B' class='latex' /> are isomorphic sets, then there must be an equivalence between the types <img src='http://s0.wp.com/latex.php?latex=F%28A%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='F(A)' title='F(A)' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=F%28B%29&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='F(B)' title='F(B)' class='latex' /> allowing us to transport objects from one &#8220;fiber&#8221; to the other.  And any function with domain <img src='http://s0.wp.com/latex.php?latex=%5Ctextsf%7BSet%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;textsf{Set}' title='&#92;textsf{Set}' class='latex' /> must respect bijection&#8212;it could be the cardinality function, for example, but it cannot be a function that would distinguish <img src='http://s0.wp.com/latex.php?latex=%5C%7B%5C%2C0%2C1%5C%2C%5C%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;{&#92;,0,1&#92;,&#92;}' title='&#92;{&#92;,0,1&#92;,&#92;}' class='latex' /> from <img src='http://s0.wp.com/latex.php?latex=%5C%7B%5C%2C%5Ctextsf%7Btrue%7D%2C%5Ctextsf%7Bfalse%7D%5C%2C%5C%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;{&#92;,&#92;textsf{true},&#92;textsf{false}&#92;,&#92;}' title='&#92;{&#92;,&#92;textsf{true},&#92;textsf{false}&#92;,&#92;}' class='latex' />.</p>
<p>Univalence allows us to formalize the informal convention of identifying things &#8220;up to isomorphism&#8221;.  In the presence of univalence equivalence types (spaces) are, in fact, <em>equal</em>.  So rather than rely on convention, we have a formal account of such identifications.</p>
<p>Higher inductives generalize ordinary inductive definitions to higher dimensions.  This means that we can now define maps (computable functions!) between, say, the 4-dimensional sphere and the 3-dimensional sphere, or between the interval and the torus.  HTT makes absolutely clear what this even means, thanks to higher inductive types.  For example, a map out of <img src='http://s0.wp.com/latex.php?latex=S%5E1&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='S^1' title='S^1' class='latex' /> is given by two pieces of data:</p>
<ol>
<li><span style="line-height:13px;">What to do with the base point.  It must be mapped to a point in the target space.</span></li>
<li>What to do with the loop.  It must be mapped to a loop in the target space based at the target point.</li>
</ol>
<p>A map out of <img src='http://s0.wp.com/latex.php?latex=I&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='I' title='I' class='latex' /> is given similarly by specifying</p>
<ol>
<li><span style="line-height:13px;">What to do with the endpoints.  These must be specified points in the target space.</span></li>
<li>What to do with the segment.  It must be a path between the specified points in the target space.</li>
</ol>
<p>It&#8217;s all just good old functional programming!  Or, rather, it <em>would</em> be, if we were to have a good computational semantics for HTT, a topic of intense interest at the IAS this year.  It&#8217;s all sort-of-obvious, yet also sort-of-non-obvious, for reasons that are difficult to explain briefly.  (If I could, they would probably be considered obvious, and not in need of much explanation!)</p>
<p>A game-changing aspect of all of this is that HTT provides a very nice foundation for mathematics in which types (<img src='http://s0.wp.com/latex.php?latex=%5Cinfty&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;infty' title='&#92;infty' class='latex' />-groupoids) play a fundamental role as classifying all mathematical objects, including proofs of propositions, which are just types.  Types may be classified according to the structure of their paths&#8212;and hence propositions may be classified according to the structure of their proofs.  For example, any two proofs of equivalence of two natural numbers are themselves equivalent; there&#8217;s only one way to say that <img src='http://s0.wp.com/latex.php?latex=2%2B2%3D4&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='2+2=4' title='2+2=4' class='latex' />, for example.  Of course there is no path between <img src='http://s0.wp.com/latex.php?latex=2%2B2&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='2+2' title='2+2' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=5&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='5' title='5' class='latex' />.  And these two situations exhaust the possibilities: any two paths between natural numbers are equal (but there may not even be one).  This unicity of paths property lifts to function spaces by extensionality, paths between functions being just paths between the range elements for each choice of domain element.  But the universe of Sets is not like this: there are many paths between sets (one for each bijection), and these are by no means equivalent.  However, there is at most one way to show that two bijections between sets are equivalent, so the structure &#8220;peters out&#8221; after dimension 2.</p>
<p>The idea to apply this kind of analysis to proofs of propositions is a distinctive feature of HTT, arising from the combination of constructivity, which gives proofs status as mathematical objects, and homotopy, which provides a powerful theory of the equivalence of proofs.  Conventional mathematics ignores proofs as objects of study, and is thus able to express certain ideas only indirectly.  HTT brings out the latent structure of proofs, and provides an elegant framework for expressing these concepts directly.</p>
<p><em>Update</em>: edited clumsy prose and added concluding paragraph.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/research/'>Research</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/homotopy-theory/'>homotopy theory</a>, <a href='http://existentialtype.wordpress.com/tag/type-theory/'>type theory</a>, <a href='http://existentialtype.wordpress.com/tag/univalence/'>univalence</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/771/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=771&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/12/03/univalent-foundations-program/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		<georss:point>40.436644 -79.927319</georss:point>
		<geo:lat>40.436644</geo:lat>
		<geo:long>-79.927319</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Introductory FP Course Materials</title>
		<link>http://existentialtype.wordpress.com/2012/09/15/introductory-fp-course-materials/</link>
		<comments>http://existentialtype.wordpress.com/2012/09/15/introductory-fp-course-materials/#comments</comments>
		<pubDate>Sat, 15 Sep 2012 19:25:22 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Teaching]]></category>
		<category><![CDATA[functional programming]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=765</guid>
		<description><![CDATA[The course materials for our first-semester introductory programming course (which I&#8217;ve discussed elsewhere on this blog) are now available here. The course materials for our second-semester data structures and algorithms course are available here. Thanks to Dan Licata and Guy Blelloch for helping make these available.  Comments are most welcome. Update: I will be giving [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=765&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>The course materials for our first-semester introductory programming course (which I&#8217;ve discussed <a title="Intro Curriculum Update" href="http://existentialtype.wordpress.com/2012/08/17/intro-curriculum-update/" target="_blank">elsewhere</a> on this blog) are now available <a title="15-150 Course Materials" href="http://www.cs.cmu.edu/~15150/previous-semesters/2012-spring" target="_blank">here</a>.</p>
<p>The course materials for our second-semester data structures and algorithms course are available <a title="15-210 Data Structures and Algorithms" href="http://www.cs.cmu.edu/afs/cs/academic/class/15210-s12/www/" target="_blank">here</a>.</p>
<p>Thanks to Dan Licata and Guy Blelloch for helping make these available.  Comments are most welcome.</p>
<p><em>Update</em>: I will be giving a talk about this at <a title="Google Pittsburgh" href="http://www.google.com/about/jobs/locations/pittsburgh/" target="_blank">Google Pittsburgh</a> on Thursday the 20th of September.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/teaching-2/'>Teaching</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/functional-programming/'>functional programming</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/765/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/765/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=765&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/09/15/introductory-fp-course-materials/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		<georss:point>40.436644 -79.927319</georss:point>
		<geo:lat>40.436644</geo:lat>
		<geo:long>-79.927319</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Yet Another Reason Not To Be Lazy Or Imperative</title>
		<link>http://existentialtype.wordpress.com/2012/08/26/yet-another-reason-not-to-be-lazy-or-imperative/</link>
		<comments>http://existentialtype.wordpress.com/2012/08/26/yet-another-reason-not-to-be-lazy-or-imperative/#comments</comments>
		<pubDate>Sun, 26 Aug 2012 22:30:27 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=753</guid>
		<description><![CDATA[In an earlier post I argued that, contrary to much of the literature in the area, parallelism is all about efficiency, and has little or nothing to do with concurrency.  Concurrency is concerned with controlling non-determinism, which can arise in all sorts of situations having nothing to do with parallelism.  Process calculi, for example, are [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=753&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In an <a title="Parallelism is not concurrency" href="http://existentialtype.wordpress.com/2011/03/17/parallelism-is-not-concurrency/">earlier post</a> I argued that, contrary to much of the literature in the area, parallelism is all about efficiency, and has little or nothing to do with concurrency.  Concurrency is concerned with controlling non-determinism, which can arise in all sorts of situations having nothing to do with parallelism.  Process calculi, for example, are best viewed as expressing <em>substructural composition</em> of programs, and have very little to do with parallel computing.  (See my <a title="PFPL" href="http://www.cs.cmu.edu/~rwh/plbook/book.pdf" target="_blank">PFPL</a> and <a title="Rob Simmons" href="http://www.cs.cmu.edu/~rjsimmon" target="_blank">Rob Simmons&#8217;</a> forthcoming Ph.D. dissertation for more on this perspective.)  Parallelism, on the other hand, is captured by analyzing the <em>cost</em> of a computation whose meaning is independent of its parallel execution.  A <em>cost semantics</em> specifies the abstract cost of a program that is validated by a <em>provable implementation</em> that transfers the abstract cost to a precise concrete cost on a particular platform.  The cost of parallel execution is neatly captured by the concept of a <em>cost graph</em> that captures the dynamic data dependencies among subcomputations.  Details such as the number of processors or the nature of the interconnect are factored into the provable implementation, which predicts the asymptotic behavior of a program on a hardware platform based on its cost graph.  One advantage of cost semantics for parallelism is that it is easy to <a title="Teaching FP to freshmen" href="http://existentialtype.wordpress.com/2011/03/15/teaching-fp-to-freshmen/" target="_blank">teach freshmen </a>how to write parallel programs; we&#8217;ve been doing this successfully for two years now, with little fuss or bother.</p>
<p>This summer <a title="Guy Blelloch" href="http://www.cs.cmu.edu/~guyb" target="_blank">Guy Blelloch </a>and I began thinking about other characterizations of the complexity of programs besides the familiar abstractions of execution time and space requirements of a computation.  One important measure, introduced by Jeff Vitter, is called <em>I/O Complexity</em>.  It measures the efficiency of algorithms with respect to <em>memory traffic</em>, a very significant determiner of performance of programs.  The model is sufficiently abstract as to encompass several different interpretations of I/O complexity.  Basically, the model assumes an unbounded <em>main memory</em> in which all data is ultimately stored, and considers a <em>cache</em> of <img src='http://s0.wp.com/latex.php?latex=M%3Dc%5Ctimes+B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='M=c&#92;times B' title='M=c&#92;times B' class='latex' /> blocked into chunks of size <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='B' title='B' class='latex' /> that provides quick access to main memory.  The complexity of algorithms is analyzed in terms of these parameters, under the assumption that in-cache accesses are cost-free, so that the only significant costs are those incurred by loading and flushing the cache.  You may interpret the abstract concepts of main memory and cache in the standard way as a two-level hierarchy representing, say, on- and off-chip memory access, or instead as representing a disk (or other storage medium) loaded into memory for processing.  The point is that the relative costs of processing cached <em>versus</em> uncached data is huge, and worth considering as a measure of the efficiency of an algorithm.</p>
<p>As usual in the algorithms world Vitter makes use of a low-level <a title="Languages and Machines" href="http://existentialtype.wordpress.com/2011/03/16/languages-and-machines/" target="_blank">machine model </a>in which to express and evaluate algorithms.  Using this model Vitter obtains a lower-bound for sorting in the I/O model, and a matching upper bound using a <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='k' title='k' class='latex' />-way merge sort, where <img src='http://s0.wp.com/latex.php?latex=k&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='k' title='k' class='latex' /> is chosen as a function of <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='M' title='M' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='B' title='B' class='latex' /> (that is, it is not cache oblivious in the sense of Leiserson, <em>et al.</em>)  Although such models provide a concrete, and well-understood, basis for analyzing algorithms, we all know full well that programming at such a low-level is at best a tedious exercise.  Worse, machine models provide no foundation for <em>composition</em> of programs, the single most important characteristic of higher-level language models.  (Indeed, the purpose of types is to mediate composition of components; without types, you&#8217;re toast.)</p>
<p>The point of Guy&#8217;s and my <a title="Cache Efficient Functional Algorithms" href="http://www.cs.cmu.edu/~rwh/papers/iolambda/short.pdf" target="_blank">work</a> this summer is to adapt the I/O model to functional programs, avoiding the mess, bother, and futility of trying to work at the machine level.  You might think that it would be impossible to reason about the cache complexity of a functional program (especially if you&#8217;re under the impression that functional programming necessarily has something to do with Haskell, which it does not, though you may perhaps say that Haskell has something to do with functional programming).  Traditional algorithms work, particularly as concerns cache complexity, is extremely finicky about memory management in order to ensure that reasonable bounds are met, and you might reasonably suspect that it will ever be thus.  The point of our paper, however, is to show that the same asymptotic bounds obtained by Vitter in the I/O model may be met using purely functional programming, provided that the functional language is (a) non-lazy (of course), and (b) implemented properly (as we describe).</p>
<p>Specifically, we give a <em>cost semantics</em> for functional programs (in the paper, a fragment of ML) that takes account of the memory traffic engendered by evaluation, and a <em>provable implementation</em> that validates the cost semantics by describing how to implement it on a machine-like model.  The crux of the matter is to account for the cache effects that arise from maintaining a <em>control stack</em> during evaluation, <em>even though</em> the abstract semantics has no concept of a stack (it&#8217;s part of the implementation, and cannot be avoided).  The cost semantics makes explicit the reading and allocation of values in the store (using Felleisen, Morrisett, and H&#8217;s &#8220;Abstract Models of Memory Management&#8221;), and imposes enough structure on the store to capture the critical concept of <em>locality</em> that is required to ensure good cache (or I/O) behavior.  The abstract model is parameterized by <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='M' title='M' class='latex' /> and <img src='http://s0.wp.com/latex.php?latex=B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='B' title='B' class='latex' /> described above, but interpreted as representing the number of <em>objects</em> in the cache and the <em>neighborhood</em> of an object in memory (the objects that are allocated near it, and that are therefore fetched along with the object whenever the cache is loaded).</p>
<p>The <em>provable implementation</em> is given in two steps.  First, we show how to transfer the abstract cost assigned to a computation into the amount of memory traffic incurred on an abstract machine with an explicit control stack.  The key idea here is an amortization argument that allows us to obtain tight bounds on the overhead required to maintain the stack.  Second, we show how to implement the crucial read and allocate operations that underpin the abstract semantics and the abstract machine.  Here we rely on a competitive analysis, given by Sleator, <em>et al.</em>, of the ideal cache model, and on an amortization of the cost of garbage collection in the style of Appel.  We also make use of an original (as far as I know) technique for implementing the control stack so as to avoid unnecessary interference with the data objects in cache.  The net result is that the cost semantics provides an accurate asymptotic analysis of the I/O complexity of a functional algorithm, provided that it is implemented in the manner we describe in the paper (which, in fact, is not far from standard implementation techniques, the only trick being how to manage the control stack properly).  We then use the model to derive bounds for several algorithms that are comparable to those obtained by Vitter using a low-level machine model.</p>
<p>The upshot of all of this is that we <em>can</em> reason about the I/O or cache complexity of functional algorithms, much as we can reason about the parallel complexity of functional algorithms, namely by using a cost semantics.  There is no need to drop down to a low-level machine model to get a handle on this important performance metric for your programs, provided, of course, that you&#8217;re not stuck with a lazy language (for those poor souls, there is no hope).</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/programming/'>Programming</a>, <a href='http://existentialtype.wordpress.com/category/research/'>Research</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/753/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/753/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=753&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/08/26/yet-another-reason-not-to-be-lazy-or-imperative/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		<georss:point>49.240157 6.996933</georss:point>
		<geo:lat>49.240157</geo:lat>
		<geo:long>6.996933</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Believing in Computer Science</title>
		<link>http://existentialtype.wordpress.com/2012/08/25/believing-in-computer-science/</link>
		<comments>http://existentialtype.wordpress.com/2012/08/25/believing-in-computer-science/#comments</comments>
		<pubDate>Sat, 25 Aug 2012 20:32:15 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Research]]></category>
		<category><![CDATA[science funding]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=737</guid>
		<description><![CDATA[It&#8217;s not every day that I can say that I agree with Bertrand Meyer, but today is an exception. Meyer has written an opinion piece in the current issue of C.ACM about science funding that I think is worth amplifying. His main point is that funding agencies, principally the NSF and the ERC, are constantly [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=737&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It&#8217;s not every day that I can say that I agree with Bertrand Meyer, but today is an exception.  Meyer has written an <a title="Bertrand Meyer CACM" href="http://portal.acm.org/ft_gateway.cfm?id=2330670&amp;ftid=1277417&amp;dwn=1&amp;##" target="_blank">opinion piece </a>in the current issue of <em>C.ACM</em> about science funding that I think is worth amplifying.  His main point is that funding agencies, principally the NSF and the ERC, are constantly pushing for &#8220;revolutionary&#8221; research, at the expense of &#8220;evolutionary&#8221; research.  Yet we all (including the funding agencies) know full well that, in almost every case, real progress is made by making seemingly small advances on what is already known, and that whether a body of research is revolutionary or not can only be assessed with considerable hindsight.  Meyer cites the example of Hoare&#8217;s formulation of his logic of programs, which was at the time a relatively small increment on Floyd&#8217;s method for proving properties of programs.  For all his brilliance, Hoare didn&#8217;t just invent this stuff out of thin air, he built on and improved upon the work that had gone before, as of course have hundreds of others built on his in turn.  This all goes without saying, or ought to, but as Meyer points out, we computer scientists are constantly bombarded with direct and indirect exhortations to abandon all that has gone before, and to make promises that no one can honestly keep.</p>
<p>Meyer&#8217;s rallying cry is for incrementalism.  It&#8217;s a tough row to hoe.  Who could possibly argue against fostering earth-shattering research that breaks new ground and summarily refutes all that has gone before?  And who could possibly defend work that is obviously just another slice of the same salami, perhaps with a bit of mustard this time?  And yet what he says is obviously true.  Funding agencies routinely <em>beg the very question under consideration</em> by stipulating <em>a priori</em> that there is something wrong with a field, and that an entirely new approach is required.  With all due respect to the people involved, I would say that calls such as these are both ill-informed and outrageously arrogant.</p>
<p>But where does this attitude come from?  Meyer cites &#8220;market envy&#8221; as one particularly powerful influence.  Funding agencies wish to see themselves as analogous to venture capitalists investing in the next big thing, losing track of the fundamental differences between basic research and product development.  (We see this sort of nonsense all the time in national politics; there is always a constituency for the absurd proposition that a government should be run like a business, as if there were any similarity at all between the two.  What they really mean is, turn the government&#8217;s money over to business, but that can&#8217;t be said too loudly for fear that people will catch on.)</p>
<p>Another influence, which Meyer doesn&#8217;t mention, seems to be a long-standing problem in computer science.  It seems to me that many researchers who move into political and administrative roles are either bored with, or do not believe in, computer science as an academic discipline.  Their own research area is, or maybe always was, boring, or has been obviated by technological developments or scientific advances.  So they move into politics, perhaps carrying a sense that there is something wrong with the field that can only be corrected by radical surgery.  They then demand that researchers do what they themselves never did in their own careers, kicking the ladder out from behind them.</p>
<p>From this somewhat contentious premise, much follows.  The constant implication, stated and unstated, that CS research is not worth doing for its own sake.  The emphasis on interdisciplinarity as an end in itself, rather than a means to an end.  The emphasis on applications to other disciplines being more important than CS itself.  The sense that &#8220;broader impacts&#8221; are far more important than the &#8220;innovative claims&#8221; (the actual work) in a research proposal.</p>
<p>Seen from this perspective, Meyer&#8217;s position is much more easily defensible.  When funding agencies are talking about &#8220;breakthroughs&#8221; and &#8220;paradigm shifts&#8221;, what they really mean is &#8220;anything but computer science&#8221;.  When Meyer talks about incrementalism, what he really means is &#8220;computer science is worth doing for its own sake&#8221;.</p>
<p>And I, for once, agree with him.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/research/'>Research</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/science-funding/'>science funding</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/737/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/737/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=737&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/08/25/believing-in-computer-science/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		<georss:point>49.240157 6.996933</georss:point>
		<geo:lat>49.240157</geo:lat>
		<geo:long>6.996933</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Polarity in Type Theory</title>
		<link>http://existentialtype.wordpress.com/2012/08/25/polarity-in-type-theory/</link>
		<comments>http://existentialtype.wordpress.com/2012/08/25/polarity-in-type-theory/#comments</comments>
		<pubDate>Sat, 25 Aug 2012 14:39:56 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[polarization]]></category>
		<category><![CDATA[type theory]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=665</guid>
		<description><![CDATA[There has recently arisen some misguided claims about a supposed opposition between functional and object-oriented programming.  The claims amount to a belated recognition of a fundamental structure in type theory first elucidated by Jean-Marc Andreoli, and developed in depth by Jean-Yves Girard in the context of logic, and by Paul Blain-Levy and Noam Zeilberger in [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=665&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>There has recently arisen some misguided claims about a supposed opposition between functional and object-oriented programming.  The claims amount to a belated recognition of a fundamental structure in type theory first elucidated by Jean-Marc Andreoli, and developed in depth by Jean-Yves Girard in the context of logic, and by Paul Blain-Levy and Noam Zeilberger in the context of programming languages.  In keeping with the general principle of computational trinitarianism, the concept of polarization has meaning in proof theory, category theory, and type theory, a sure sign of its fundamental importance.</p>
<p>Polarization is not an issue of language design, it is an issue of type structure.  The main idea is that types may be classified as being <em>positive</em> or <em>negative</em>, with the positive being characterized by their structure and the negative being characterized by their behavior.  In a sufficiently rich type system one may consider, and make effective use of, both positive and negative types.  There is nothing remarkable or revolutionary about this, and, truly, there is nothing really new about it, other than the terminology.  But through the efforts of the above-mentioned researchers, and others, we have learned quite a lot about the importance of polarization in logic, languages, and semantics.  I find it particularly remarkable that Andreoli&#8217;s work on proof search turned out to also be of deep significance for programming languages.  This connection was developed and extended by Zeilberger, on whose <a title="Noam Zeilberger Dissertation" href="http://www.cs.cmu.edu/~rwh/theses/zeilberger.pdf" target="_blank">dissertation</a> I am basing this post.</p>
<p>The simplest and most direct way to illustrate the ideas is to consider the product type, which corresponds to conjunction in logic.  There are two possible ways that one can formulate the rules for the product type that from the point of view of inhabitation are completely equivalent, but from the point of view of computation are quite distinct.  Let us first state them as rules of logic, then equip these rules with proof terms so that we may study their operational behavior.  For the time being I will refer to these as Method 1 and Method 2, but after we examine them more carefully, we will find more descriptive names for them.</p>
<p>Method 1 of defining conjunction is perhaps the most familiar.  It consists of this introduction rule</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cfrac%7B%5CGamma%5Cvdash+A%5C%3B%5Ctextsf%7Btrue%7D%5Cquad%5CGamma%5Cvdash+B%5C%3B%5Ctextsf%7Btrue%7D%7D%7B%5CGamma%5Cvdash+A%5Cwedge+B%5C%3B%5Ctextsf%7Btrue%7D%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash A&#92;;&#92;textsf{true}&#92;quad&#92;Gamma&#92;vdash B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}' title='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash A&#92;;&#92;textsf{true}&#92;quad&#92;Gamma&#92;vdash B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}' class='latex' /></p>
<p>and the following two elimination rules</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cfrac%7B%5CGamma%5Cvdash+A%5Cwedge+B%5C%3B%5Ctextsf%7Btrue%7D%7D%7B%5CGamma%5Cvdash+A%5C%3B%5Ctextsf%7Btrue%7D%7D%5Cqquad%5Cfrac%7B%5CGamma%5Cvdash+A%5Cwedge+B%5C%3B%5Ctextsf%7Btrue%7D%7D%7B%5CGamma%5Cvdash+B%5C%3B%5Ctextsf%7Btrue%7D%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash A&#92;;&#92;textsf{true}}&#92;qquad&#92;frac{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash B&#92;;&#92;textsf{true}}' title='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash A&#92;;&#92;textsf{true}}&#92;qquad&#92;frac{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash B&#92;;&#92;textsf{true}}' class='latex' />.</p>
<p>Method 2 of defining conjunction is only slightly different.  It consists of the same introduction</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B%5CGamma%5Cvdash+A%5C%3B%5Ctextsf%7Btrue%7D%5Cquad%5CGamma%5Cvdash+B%5C%3B%5Ctextsf%7Btrue%7D%7D%7B%5CGamma%5Cvdash+A%5Cwedge+B%5C%3B%5Ctextsf%7Btrue%7D%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;frac{&#92;Gamma&#92;vdash A&#92;;&#92;textsf{true}&#92;quad&#92;Gamma&#92;vdash B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}' title='&#92;displaystyle &#92;frac{&#92;Gamma&#92;vdash A&#92;;&#92;textsf{true}&#92;quad&#92;Gamma&#92;vdash B&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true}}' class='latex' /></p>
<p>and one elimination rule</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cfrac%7B%5CGamma%5Cvdash+A%5Cwedge+B%5C%3B%5Ctextsf%7Btrue%7D+%5Cquad+%5CGamma%2CA%5C%3B%5Ctextsf%7Btrue%7D%2CB%5C%3B%5Ctextsf%7Btrue%7D%5Cvdash+C%5C%3B%5Ctextsf%7Btrue%7D%7D%7B%5CGamma%5Cvdash+C%5C%3B%5Ctextsf%7Btrue%7D%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true} &#92;quad &#92;Gamma,A&#92;;&#92;textsf{true},B&#92;;&#92;textsf{true}&#92;vdash C&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash C&#92;;&#92;textsf{true}}' title='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash A&#92;wedge B&#92;;&#92;textsf{true} &#92;quad &#92;Gamma,A&#92;;&#92;textsf{true},B&#92;;&#92;textsf{true}&#92;vdash C&#92;;&#92;textsf{true}}{&#92;Gamma&#92;vdash C&#92;;&#92;textsf{true}}' class='latex' />.</p>
<p>From a logical point of view the two formulations are interchangeable in that the rules of the one are admissible with respect to the rules of the other, given the usual structural properties of entailment, specifically reflexivity and transitivity.  However, one can discern a difference in &#8220;attitude&#8221; in the two formulations that will turn out to be a manifestation of the concept of polarity.</p>
<p>Method 1 is a formulation of the idea that a proof of a conjunction is <em>anything that behaves conjunctively</em>, which means that it supports the two elimination rules given in the definition.  There is no commitment to the internal structure of a proof, nor to the details of how projection operates; as long as there are projections, then we are satisfied that the connective is indeed conjunction.  We may consider that the elimination rules define the connective, and that the introduction rule is derived from that requirement.  Equivalently we may think of the proofs of conjunction as being <em>coinductively defined</em> to be as large as possible, as long as the projections are available.  Zeilberger calls this the <em>pragmatist</em> interpretation, following Count Basie&#8217;s principle, &#8220;if it sounds good, it is good.&#8221;</p>
<p>Method 2 is a direct formulation of the idea that the proofs of a conjunction are <em>inductively defined</em> to be as small as possible, as long as the introduction rule is valid.  Specifically, the single introduction rule may be understood as defining the structure of the sole form of proof of a conjunction, and the single elimination rule expresses the induction, or recursion, principle associated with that viewpoint.  Specifically, to reason from the fact that <img src='http://s0.wp.com/latex.php?latex=A%5Cwedge+B%5C%3B%5Ctextsf%7Btrue%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A&#92;wedge B&#92;;&#92;textsf{true}' title='A&#92;wedge B&#92;;&#92;textsf{true}' class='latex' /> to derive <img src='http://s0.wp.com/latex.php?latex=C%5C%3B%5Ctextsf%7Btrue%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='C&#92;;&#92;textsf{true}' title='C&#92;;&#92;textsf{true}' class='latex' />, it is enough to reason from the data that went into the proof of the conjunction to derive <img src='http://s0.wp.com/latex.php?latex=C%5C%3B%5Ctextsf%7Btrue%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='C&#92;;&#92;textsf{true}' title='C&#92;;&#92;textsf{true}' class='latex' />.  We may consider that the introduction rule defines the connective, and that the elimination rule is derived from that definition.  Zeilberger calls this the <em>verificationist</em> interpretation.</p>
<p>These two perspectives may be clarified by introducing proof terms, and the associated notions of reduction that give rise to a dynamics of proofs.</p>
<p>When reformulated with explicit proofs, the rules of Method 1 are the familiar rules for ordered pairs:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cfrac%7B%5CGamma%5Cvdash+M%3AA%5Cquad%5CGamma%5Cvdash+N%3AB%7D%7B%5CGamma%5Cvdash+%5Clangle+M%2C+N%5Crangle%3AA%5Cwedge+B%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash M:A&#92;quad&#92;Gamma&#92;vdash N:B}{&#92;Gamma&#92;vdash &#92;langle M, N&#92;rangle:A&#92;wedge B}' title='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash M:A&#92;quad&#92;Gamma&#92;vdash N:B}{&#92;Gamma&#92;vdash &#92;langle M, N&#92;rangle:A&#92;wedge B}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cfrac%7B%5CGamma%5Cvdash+M%3AA%5Cwedge+B%7D%7B%5CGamma%5Cvdash+%5Ctextsf%7Bfst%7D%28M%29%3AA%7D%5Cqquad%5Cfrac%7B%5CGamma%5Cvdash+M%3AA%5Cwedge+B%7D%7B%5CGamma%5Cvdash+%5Ctextsf%7Bsnd%7D%28M%29%3AB%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash M:A&#92;wedge B}{&#92;Gamma&#92;vdash &#92;textsf{fst}(M):A}&#92;qquad&#92;frac{&#92;Gamma&#92;vdash M:A&#92;wedge B}{&#92;Gamma&#92;vdash &#92;textsf{snd}(M):B}' title='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash M:A&#92;wedge B}{&#92;Gamma&#92;vdash &#92;textsf{fst}(M):A}&#92;qquad&#92;frac{&#92;Gamma&#92;vdash M:A&#92;wedge B}{&#92;Gamma&#92;vdash &#92;textsf{snd}(M):B}' class='latex' />.</p>
<p>The associated reduction rules specify that the elimination rules are post-inverse to the introduction rules:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Ctextsf%7Bfst%7D%28%5Clangle+M%2CN%5Crangle%29%5Cmapsto+M+%5Cqquad+%5Ctextsf%7Bsnd%7D%28%5Clangle+M%2CN%5Crangle%29%5Cmapsto+N&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;textsf{fst}(&#92;langle M,N&#92;rangle)&#92;mapsto M &#92;qquad &#92;textsf{snd}(&#92;langle M,N&#92;rangle)&#92;mapsto N' title='&#92;displaystyle&#92;textsf{fst}(&#92;langle M,N&#92;rangle)&#92;mapsto M &#92;qquad &#92;textsf{snd}(&#92;langle M,N&#92;rangle)&#92;mapsto N' class='latex' />.</p>
<p>In this formulation the proposition <img src='http://s0.wp.com/latex.php?latex=A%5Cwedge+B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A&#92;wedge B' title='A&#92;wedge B' class='latex' /> is often written <img src='http://s0.wp.com/latex.php?latex=A%5Ctimes+B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A&#92;times B' title='A&#92;times B' class='latex' />, since it behaves like a Cartesian product of proofs.</p>
<p>When formulated with explicit proofs, Method 2 looks like this:</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle+%5Cfrac%7B%5CGamma%5Cvdash+M%3AA%5Cquad%5CGamma%5Cvdash+M%3AB%7D%7B%5CGamma%5Cvdash+M%5Cotimes+N%3AA%5Cwedge+B%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle &#92;frac{&#92;Gamma&#92;vdash M:A&#92;quad&#92;Gamma&#92;vdash M:B}{&#92;Gamma&#92;vdash M&#92;otimes N:A&#92;wedge B}' title='&#92;displaystyle &#92;frac{&#92;Gamma&#92;vdash M:A&#92;quad&#92;Gamma&#92;vdash M:B}{&#92;Gamma&#92;vdash M&#92;otimes N:A&#92;wedge B}' class='latex' /></p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Cfrac%7B%5CGamma%5Cvdash+M%3AA%5Cwedge+B+%5Cquad+%5CGamma%2Cx%3AA%2Cy%3AB%5Cvdash+N%3AC%7D%7B%5CGamma%5Cvdash+%5Ctextsf%7Bsplit%7D%28M%3Bx%2Cy.N%29%3AC%7D&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash M:A&#92;wedge B &#92;quad &#92;Gamma,x:A,y:B&#92;vdash N:C}{&#92;Gamma&#92;vdash &#92;textsf{split}(M;x,y.N):C}' title='&#92;displaystyle&#92;frac{&#92;Gamma&#92;vdash M:A&#92;wedge B &#92;quad &#92;Gamma,x:A,y:B&#92;vdash N:C}{&#92;Gamma&#92;vdash &#92;textsf{split}(M;x,y.N):C}' class='latex' /></p>
<p>with the reduction rule</p>
<p><img src='http://s0.wp.com/latex.php?latex=%5Cdisplaystyle%5Ctextsf%7Bsplit%7D%28M%5Cotimes+N%3Bx%2Cy.P%29%5Cmapsto+%5BM%2CN%2Fx%2Cy%5DP&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='&#92;displaystyle&#92;textsf{split}(M&#92;otimes N;x,y.P)&#92;mapsto [M,N/x,y]P' title='&#92;displaystyle&#92;textsf{split}(M&#92;otimes N;x,y.P)&#92;mapsto [M,N/x,y]P' class='latex' />.</p>
<p>With this formulation it is natural to write <img src='http://s0.wp.com/latex.php?latex=A%5Cwedge+B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A&#92;wedge B' title='A&#92;wedge B' class='latex' /> as <img src='http://s0.wp.com/latex.php?latex=A%5Cotimes+B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='A&#92;otimes B' title='A&#92;otimes B' class='latex' />, since it behaves like a tensor product of proofs.</p>
<p>Since the two formulations of &#8220;conjunction&#8221; have different internal structure, we may consider them as <em>two different connectives</em>.  This may, at first, seem pointless, because it is easily seen that <img src='http://s0.wp.com/latex.php?latex=x%3AA%5Ctimes+B%5Cvdash+M%3AA%5Cotimes+B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x:A&#92;times B&#92;vdash M:A&#92;otimes B' title='x:A&#92;times B&#92;vdash M:A&#92;otimes B' class='latex' /> for some <img src='http://s0.wp.com/latex.php?latex=M&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='M' title='M' class='latex' /> and that <img src='http://s0.wp.com/latex.php?latex=x%3AA%5Cotimes+B%5Cvdash+N%3AA%5Ctimes+B&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='x:A&#92;otimes B&#92;vdash N:A&#92;times B' title='x:A&#92;otimes B&#92;vdash N:A&#92;times B' class='latex' /> for some <img src='http://s0.wp.com/latex.php?latex=N&amp;bg=ffffff&amp;fg=333333&amp;s=0' alt='N' title='N' class='latex' />, so that the two connectives are logically equivalent, and hence interchangeable in any proof.  But there is nevertheless a reason to draw the distinction, namely that they have different dynamics.</p>
<p>It is easy to see why.  From the pragmatic perspective, since the projections act independently of one another, there is no reason to insist that the components of a pair be evaluated before they are used.  Quite possibly we may only ever project the first component, so why bother with the second?  From the verificationist perspective, however, we are pattern matching against the proof of the conjunction, and are demanding both components at once, so it makes sense to evaluate both components of a pair in anticipation of future pattern matching.  (Admittedly, in a structural type theory one may immediately drop one of the variables on the floor and never use it, but then why give it a name at all?  In a substructural type theory such as linear type theory, this is not a possibility, and the interpretation is forced.)  Thus, the verficationist formulation corresponds to <em>eager</em> evaluation of pairing, and the pragmatist formulation to <em>lazy</em> evaluation of pairing.</p>
<p>Having distinguished the two forms of conjunction by their operational behavior, it is immediately clear that both forms are useful, and are by no means opposed to one another.  This is why, for example, the concept of a <em>lazy language</em> makes no sense, rather one should instead speak of <em>lazy types</em>, which are perfectly useful, but by no means the only types one should ever consider.  Similarly, the concept of an <em>object-oriented language</em> makes no sense, because it amounts to focusing attention solely on the pragmatist conception, to the exclusion of the verificationist, by insisting that only the elimination forms (the so-called &#8220;methods&#8221;) are relevant in defining an object, and not the introduction forms.</p>
<p>More broadly, it is useful to classify types into two <em>polarities</em>, the <em>positive</em> and the <em>negative</em>, corresponding to the verificationist and pragmatist perspectives.  Positive types are <em>inductively defined</em> by their introduction forms; they correspond to <em>colimits</em>, or <em>direct limits</em>, in category theory.  Negative types are <em>coinductively defined</em> by their elimination forms; they correspond to <em>limits</em>, or <em>inverse limits</em>, in category theory.  The concept of polarity is intimately related to the concept of <em>focusing</em>, which in logic sharpens the concept of a cut-free proof and elucidates the distinction between synchronous and asynchronous connectives, and which in programming languages provides an elegant account of pattern matching, continuations, and effects.</p>
<p>As ever, enduring principles emerge from the interplay between proof theory, category theory, and type theory.  Such concepts are found in nature, and do not depend on cults of personality or the fads of the computer industry for their existence or importance.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/programming/'>Programming</a>, <a href='http://existentialtype.wordpress.com/category/research/'>Research</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/polarization/'>polarization</a>, <a href='http://existentialtype.wordpress.com/tag/type-theory/'>type theory</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/665/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/665/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=665&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/08/25/polarity-in-type-theory/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		<georss:point>49.240157 6.996933</georss:point>
		<geo:lat>49.240157</geo:lat>
		<geo:long>6.996933</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Intro Curriculum Update</title>
		<link>http://existentialtype.wordpress.com/2012/08/17/intro-curriculum-update/</link>
		<comments>http://existentialtype.wordpress.com/2012/08/17/intro-curriculum-update/#comments</comments>
		<pubDate>Fri, 17 Aug 2012 13:11:58 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Teaching]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[imperative programming]]></category>
		<category><![CDATA[parallelism]]></category>
		<category><![CDATA[verification]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=650</guid>
		<description><![CDATA[In previous posts I have talked about the new introductory CS curriculum under development at Carnegie Mellon. After a year or so of planning, we began to roll out the new curriculum in the Spring of 2011, and have by now completed the transition. As mentioned previously, the main purpose is to bring the introductory [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=650&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>In previous posts I have talked about the <a title="Teaching FP to freshmen" href="http://existentialtype.wordpress.com/2011/03/15/teaching-fp-to-freshmen/">new introductory CS curriculum</a> under development at Carnegie Mellon. After a year or so of planning, we began to roll out the new curriculum in the Spring of 2011, and have by now completed the transition. As mentioned previously, the main purpose is to bring the introductory sequence up to date, with particular emphasis on introducing parallelism and verification. A secondary purpose was to restore the focus on computing fundamentals, and correct the drift towards complex application frameworks that offer the students little sense of what is really going on. (The poster child was a star student who admitted that, although she had built a web crawler the previous semester, she in fact has no idea how to build a web crawler.) A particular problem is that what should have been a grounding in the fundamentals of algorithms and data structures turned into an exercise in object-oriented programming, swamping the core content with piles of methodology of dubious value to beginning students. (There is a new, separate, upper-division course on oo methodology for students interested in this topic.) A third purpose was to level the playing field, so that students who had learned about programming on the street were equally as challenged, if not more so, than students without much or any such experience. One consequence would be to reduce the concomitant bias against women entering CS, many fewer of whom having prior computing experience than the men.</p>
<p>The solution was a complete do-over, jettisoning the traditional course completely, and starting from scratch. The most important decision was to emphasize functional programming right from the start, and to build on this foundation for teaching data structures and algorithms. Not only does FP provide a much more natural starting point for teaching programming, it is infinitely more amenable to rigorous verification, and provides a natural model for <a title="Parallelism is not concurrency" href="http://existentialtype.wordpress.com/2011/03/17/parallelism-is-not-concurrency/">parallel computation</a>. Every student comes to university knowing some algebra, and they are therefore familiar with the idea of computing by calculation (after all, the word algebra derives from the Arabic al jabr, meaning system of calculation). Functional programming is a generalization of algebra, with a richer variety of data structures and a richer set of primitives, so we can build on that foundation. It is critically important that variables in FP are, in fact, mathematical variables, and not some <a title="Words matter" href="http://existentialtype.wordpress.com/2012/02/01/words-matter/">distorted facsimile </a>thereof, so all of their mathematical intuitions are directly applicable. So we can immediately begin discussing verification as a natural part of programming, using principles such as mathematical induction and equational reasoning to guide their thinking. Moreover, there are natural concepts of sequential time complexity, given by the number of steps required to calculate an answer, and parallel time complexity, given by the data dependencies in a computation (often made manifest by the occurrences of variables). These central concepts are introduced in the first week, and amplified throughout the semester.</p>
<p>Two major homework exercises embody the high points of the first-semester course, one to do with co-development of code with proof, the other to do with parallelism. Co-development of program and proof is illustrated by an online regular expression matcher. The problem is a gem for several reasons. One is that it is essentially impossible for anyone to solve by debugging a blank screen. This sets us up nicely for explaining the importance of specification and proof as part of the development process. Another is that it is very easy, almost inevitable, for students to make mistakes that are not easily caught or diagnosed by testing. We require the students to carry out a proof of the correctness of the matcher, and in the process discover a point where the proof breaks down, which then leads to a proper solution. (See my JFP paper &#8220;Proof-Directed Debugging&#8221; for a detailed development of the main ideas.) The matcher also provides a very nice lesson in the use of higher-order functions to capture patterns of control, resulting in an extremely clean and simple matcher whose correctness proof is highly non-trivial.</p>
<p>The main parallelism example is the Barnes-Hut algorithm for solving the n-body problem in physics. Barnes-Hut is an example of a &#8220;tree-based&#8221; method, invented by Andrew Appel, for solving this well-known problem. At a high level the main idea is to decompose space into octants (or quadrants if you&#8217;re working in the plane), recursively solving the problem for each octant and then combining the solutions to make an overall solution. The key idea is to use an approximation for bodies that are far enough away&#8212;a distant constellation can be regarded as an atomic body for the purposes of calculating the effects of its stars on the sun, say. The problem is naturally parallelizable, because of the recursive decomposition. Moreover, it provides a very nice link to their high school physics. Since FP is just an extension of mathematics, the equations specifying the force law and Newton&#8217;s Law carry over directly to the code. This is an important sense in which FP builds on and amplifies their prior mathematical experience, and shows how one may connect computer science with other sciences in a rather direct manner.</p>
<p>The introductory FP course establishes the basis for the new data structures and algorithms course that most students take in either the third or fourth semester. This course represents a radical departure from tradition in several ways. First, it is a highly rigorous course in algorithms that rivals the upper-division course taught at most universities (including our own) for the depth and breadth of ideas it develops. Second, it takes the stance that all algorithms are parallel algorithms, with sequential being but a special case of parallel. Of course some algorithms have a better parallelizability ratio (a precise technical characterization of the ability to make use of parallelism), and this can be greatly affected by data structure selection, among other considerations. Third, the emphasis is on persistent abstract types, which are indispensable for parallel computing. No more linked lists, no more null pointer nonsense, no more mutation. Instead we consider abstract types of graphs, trees, heaps, and so forth, all with a persistent semantics (operations create &#8220;new&#8221; ones, rather than modify &#8220;old&#8221; ones). Fourth, we build on the reasoning methods introduced in the first semester course to prove the correctness and the efficiency of algorithms. Functional programming makes all of this possible. Programs are concise and amenable to proof, they are naturally parallel, and they enjoy powerful typing properties that enforce abstraction in a mathematically rigorous manner. Fifth, there is a strong emphasis on problems of practical interest. For example, homework 1 is the shotgun method for genome sequencing, a parallel algorithm of considerable practical importance and renown.</p>
<p>There is a third introductory course in imperative programming, taken in either the first or second semester (alternating with the functional programming course at the student&#8217;s discretion), that teaches the &#8220;old ways&#8221; of doing things using a &#8220;safe&#8221; subset of C. Personally, I think this style of programming is obsolete, but there are many good reasons to continue to teach it, the biggest probably being the legacy problem. The emphasis is on verification, using simple assertions that are checked at run-time and which may be verified statically in some situations. It is here that students learn how to do things &#8220;the hard way&#8221; using low-level representations. This course is very much in the style of the 1970&#8242;s era data structures course, the main difference being that the current incarnation of Pascal has curly braces, rather than begin-end.</p>
<p>For the sake of those readers who may not be up to date on such topics, it seems important to emphasize that <a title="What is a functional language?" href="http://existentialtype.wordpress.com/2011/03/16/what-is-a-functional-language/">functional programming</a> <em>subsumes</em> imperative programming. Every functional language is capable of expressing the old-fashioned sequential pointer-hacking implementation of data structures. You can even reproduce Tony Hoare&#8217;s self-described &#8220;billion dollar mistake&#8221; of the cursed &#8220;<a title="Boolean Blindness" href="http://existentialtype.wordpress.com/2011/03/15/boolean-blindness/">null pointer</a>&#8221; if you&#8217;d like! But the whole point is that it is rarely useful, and almost never elegant, to work that way. (Curiously, the &#8220;<a title="Of Course ML Has Monads!" href="http://existentialtype.wordpress.com/2011/05/01/of-course-ml-has-monads/">monad mania</a>&#8221; in the Haskell community stresses an imperative, sequential style of programming that is incompatible with parallelism, but this is not forced on you as it is in the imperative world.) From this point of view there no loss, and considerable gain, in teaching functional programming from the start. It puts a proper emphasis on mathematically sane programming methods, but allows for mutation-based programming where appropriate (for example, in engendering &#8220;side effects&#8221; on users).</p>
<p>To learn more about these courses, please see the course web pages:</p>
<ul>
<li><a title="Imperative Programming" href="http://www.cs.cmu.edu/~fp/courses/15122-s11/" target="_blank">Imperative Programming</a>.</li>
<li><a title="Functional Programming" href="http://www.cs.cmu.edu/~15150/" target="_blank">Functional Programming</a>.</li>
<li><a title="Data Structures and Algorithms" href="http://www.cs.cmu.edu/~15210/" target="_blank">Data Structures and Algorithms</a></li>
</ul>
<p>I encourage readers to review the syllabi and course materials. There is quite a large body of material in place that we plan to expand into textbook-level treatments in the near future. We also plan to write a journal article documenting our experiences with these courses.</p>
<p>I am very grateful to my colleagues Guy Blelloch, Dan Licata, and Frank Pfenning for their efforts in helping to develop the new introductory curriculum at Carnegie Mellon, and to the teaching assistants whose hard work and dedication put the ideas into practice.</p>
<p><em>Update</em>: Unfortunately, the homework assignments for these courses are not publicly available, because we want to minimize the temptation for students to make use of old assignments and solutions in preparing their own work.  I am working with my colleagues to find some way in which we can promote the ideas without sacrificing too much of the integrity of the course materials.  I apologize for the inconvenience.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/teaching-2/'>Teaching</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/functional-programming/'>functional programming</a>, <a href='http://existentialtype.wordpress.com/tag/imperative-programming/'>imperative programming</a>, <a href='http://existentialtype.wordpress.com/tag/parallelism/'>parallelism</a>, <a href='http://existentialtype.wordpress.com/tag/verification/'>verification</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/650/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/650/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=650&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/08/17/intro-curriculum-update/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		<georss:point>49.240157 6.996933</georss:point>
		<geo:lat>49.240157</geo:lat>
		<geo:long>6.996933</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
		<item>
		<title>Haskell Is Exceptionally Unsafe</title>
		<link>http://existentialtype.wordpress.com/2012/08/14/haskell-is-exceptionally-unsafe/</link>
		<comments>http://existentialtype.wordpress.com/2012/08/14/haskell-is-exceptionally-unsafe/#comments</comments>
		<pubDate>Tue, 14 Aug 2012 10:57:52 +0000</pubDate>
		<dc:creator>Robert Harper</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[exceptions]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[ml]]></category>
		<category><![CDATA[monads]]></category>
		<category><![CDATA[safety]]></category>

		<guid isPermaLink="false">http://existentialtype.wordpress.com/?p=627</guid>
		<description><![CDATA[It is well known that Haskell is not type safe.  The most blatant violation is the all too necessary, but aptly named, unsafePerformIO operation.  You are enjoined not to use this in an unsafe manner, and must be careful to ensure that the encapsulated computation may be executed at any time because of the inherent [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=627&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
				<content:encoded><![CDATA[<p>It is well known that Haskell is not type safe.  The most blatant violation is the all too necessary, but aptly named, <strong>unsafePerformIO</strong> operation.  You are enjoined not to use this in an unsafe manner, and must be careful to ensure that the encapsulated computation may be executed at any time because of the inherent unpredictability of lazy evaluation.  (The analogous operation in <a title="Of Course ML Has Monads!" href="http://existentialtype.wordpress.com/2011/05/01/of-course-ml-has-monads/">monadic ML</a>, <strong>safePerformIO</strong>, is safe, because of the value restriction on polymorphism.)  A less blatant violation is that the equational theory of the language with <strong>seq</strong> is different from the equational theory without it, and the last I knew the GHC compiler was willing to make transformations that are valid only in the absence of this construct.  This too is well known.  A proper reformulation of the equational theory was given by Patricia Johann a few years ago as a step towards solving it.  (If the GHC compiler is no longer unsafe in this respect, it would be good to know.)</p>
<p>I&#8217;ve asked around a little bit, including some of the Haskell insiders, whether it is equally well known that the typed exception mechanism in Haskell is unsound.  From what I can tell this seems not to be as well-understood, so let me explain the situation as I see it, and I am sure I will be quickly corrected if I am wrong.  The starting point for me was the realization that in Haskell pure code (outside of the IO monad) may raise an exception, and, importantly for my point, the exceptions are user-defined.  Based on general semantic considerations, it seemed to me that this cannot possibly be sound, and Karl Crary helped me to isolate the source of the problem.</p>
<p>The difficulty is really nothing to do with exceptions <em>per se</em>, but rather with <em>exception values</em>.  (So my point has nothing whatsoever to do with imprecise exceptions.)  It seems to me that the root cause is an all-too-common misunderstanding of the concept of <em>typed exceptions</em> as they occur, for example, in Standard ML.  The mistake is a familiar one, the confusion of types with classes; it arises often in discussions related to oop.  To clarify the situation let me begin with a few remarks exception values in ML, and then move on to the issue at hand.</p>
<p>The first point, which is not particularly relevant to the present discussion, is that <em>exceptions have nothing to do with dynamic binding</em>.  The full details are in my <a title="PFPL" href="http://www.cs.cmu.edu/~rwh/plbook/book.pdf" target="_blank">book</a>, so I will only summarize the situation here.  Many seem to have the idea that an exception handler, which typically looks like a sequence of clauses consisting of an exception and an action, amounts to a dynamic binding of each exception to its associated handler.  This is not so.  In fact the left-hand side of an exception clause is a<em> patter</em><em>n</em>, including a variable (of which a wild card is one example), or nested patterns of exceptions and values.  I realize that one may <em>implement</em> the exception mechanism using a single dynamically bound symbol holding the current exception handler, but this implementation is but one of many possible ones, and does not in any case define the <em>abstraction</em> of exceptions.  Exceptions have no more to do with dynamic binding than does the familiar if-then-else available in any language.</p>
<p>The second point, which is pertinent to this discussion, is that <em>exceptions have only one type</em>.  You read that right: the typed exception mechanism in Standard ML is, in fact, uni-typed (where I have I heard <a title="Dynamic languages are static languages" href="http://existentialtype.wordpress.com/2011/03/19/dynamic-languages-are-static-languages/" target="_blank">that</a> before?).  It is perfectly true that in Standard ML one may associate a value of any type you like with an exception, and this value may be communicated to the handler of that exception.  But it is perfectly false to say that there are multiple types of exceptions; there is only one, but it has many (in fact, &#8220;dynamically many&#8221;) classes.  When you declare, say, <strong>exception Error of string</strong> in Standard ML you are introducing a new <em>class</em> of type<em> </em><strong>string-&gt;exn</strong>, so that <strong>Error </strong><em>s</em> is an exception value of type <strong>exn</strong> carrying a string.  An exception handler associates to a computation of type <strong>α</strong> a function of type <strong>exn-&gt;α </strong>that handles any exceptions thrown by that computation.  To propagate uncaught exceptions, the handler is  implicitly post-composed with the handler <strong>fn </strong><strong>x =&gt; raise x</strong>.  Pattern matching recovers the type of the associated value in the branch that handles a particular exception.  So, for example, a handler of the form <strong>Error x =&gt;</strong> <strong><em>exp</em></strong> propagates the fact that <strong>x</strong> has type <strong>string</strong> into the expression <strong><em>exp</em></strong>, and similarly for any other exception carrying any other type.  (Incidentally, another perfectly good handler is <strong>Error &#8220;abcdef&#8221; =&gt; <em>exp</em></strong><em>,</em> which handles only an <strong>Error</strong> exception with associated value <strong>&#8220;abcdef&#8221;</strong>, and no other.  This debunks the dynamic binding interpretation mentioned earlier.)<span style="text-decoration:underline;"><em><br />
</em></span></p>
<p>The third point is that exception classes are <em>dynamically generated </em>in the sense that each evaluation of an exception declaration generates a fresh exception.  This is absolutely essential for modularity, and is extremely useful for a wide variety of other purposes, including managing information flow security within a program. (See Chapter 34 of my <a title="PFPL" href="http://www.cs.cmu.edu/~rwh/plbook/book.pdf" target="_blank">book</a> for a fuller discussion.)  O&#8217;Caml attempted to impose a static form of exceptions, but it is now recognized that this does not work properly in the presence of functors or separate compilation.  This means that exception declarations are inherently stateful and cannot be regarded as pure.</p>
<p>This got me to wondering how Haskell could get away with user-defined typed exceptions in &#8220;pure&#8221; code.  The answer seems to be &#8220;it can&#8217;t&#8221;, as the following example illustrates:</p>
<p><strong>import Control.Exception</strong></p>
<p><strong>import Data.Typeable</strong></p>
<p><strong>newtype Foo = Foo (() -&gt; IO ())</strong></p>
<p><strong>{- set Foo&#8217;s TypeRep to be the same as ErrorCall&#8217;s -}</strong></p>
<p><strong>instance Typeable Foo where</strong></p>
<p><strong>  typeOf _ = typeOf (undefined :: ErrorCall)</strong></p>
<p><strong>instance Show Foo where  show _ = &#8220;&#8221;</strong></p>
<p><strong>instance Exception Foo</strong></p>
<p><strong>main = Control.Exception.catch (error &#8220;kaboom&#8221;) (\ (Foo f) -&gt; f ())</strong></p>
<p>If you run this code in GHC, you get &#8220;internal error: stg_ap_v_ret&#8221;, which amounts to &#8220;going wrong.&#8221;  The use of exceptions is really incidental, except insofar as it forces the use of the class <strong>Typeable</strong>, which is exploited here.</p>
<p>How are we to understand this unsoundness?  My own diagnosis is that typed exceptions are mis-implemented in Haskell using types, rather than classes.  There is no need in ML for any form of type casting to implement exceptions, because there is exactly one type of exception values, albeit one with many classes.  Haskell, on the other hand, tries to have exceptions with different types<em>.</em>  This immediately involves us in type casting, and hilarity ensues.</p>
<p>The problem appears to be difficult to fix, because to do so would require that exception values be declared within the IO monad, which runs against the design principle (unavoidable, in my opinion) that exceptions are permissible in pure code.  (Exceptions are, according to Aleks Nanevski, co-monadic, not monadic.)  Alternatively, since Haskell lacks modularity, a possible fix is to permit only static exceptions in essentially the style proposed in O&#8217;Caml.  This amounts to collecting up the exception declarations on a whole-program basis, and implicitly making a global <strong>data</strong> declaration that declares all the exception constructors &#8220;up front&#8221;.  Exception handlers would then work by pattern matching, and all would be well.  Why this is not done already is a mystery to me; the current strategy looks a lot like a kludge once you see the problem with safety.</p>
<p>Insofar as my interpretation of what is going on here is correct, the example once again calls into question the dogma of the separation of Church from state as it is realized in Haskell.  As beguiling as it is, the idea, in its current form, simply does not work.  Dave MacQueen recently described it to me as a &#8220;tar baby&#8221;, from the Brer Rabbit story: the more you get involved with it, the more entangled you become.</p>
<br />Filed under: <a href='http://existentialtype.wordpress.com/category/programming/'>Programming</a>, <a href='http://existentialtype.wordpress.com/category/research/'>Research</a> Tagged: <a href='http://existentialtype.wordpress.com/tag/exceptions/'>exceptions</a>, <a href='http://existentialtype.wordpress.com/tag/haskell/'>Haskell</a>, <a href='http://existentialtype.wordpress.com/tag/ml/'>ml</a>, <a href='http://existentialtype.wordpress.com/tag/monads/'>monads</a>, <a href='http://existentialtype.wordpress.com/tag/safety/'>safety</a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/existentialtype.wordpress.com/627/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/existentialtype.wordpress.com/627/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=existentialtype.wordpress.com&#038;blog=2157150&#038;post=627&#038;subd=existentialtype&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://existentialtype.wordpress.com/2012/08/14/haskell-is-exceptionally-unsafe/feed/</wfw:commentRss>
		<slash:comments>50</slash:comments>
		<georss:point>49.240157 6.996933</georss:point>
		<geo:lat>49.240157</geo:lat>
		<geo:long>6.996933</geo:long>
		<media:content url="http://0.gravatar.com/avatar/9a3bf4aba89a3d8f593ec29e75e5884a?s=96&#38;d=monsterid&#38;r=G" medium="image">
			<media:title type="html">abstract type</media:title>
		</media:content>
	</item>
	</channel>
</rss>
