<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Blog feed</title>
		<link>http://syntax.wikidot.com</link>
		<description></description>
				<copyright></copyright>
		<lastBuildDate>Thu, 12 Mar 2026 20:42:13 +0000</lastBuildDate>
		
					<item>
				<guid>http://syntax.wikidot.com/blog:11</guid>
				<title>Turing&#039;s Euclidean Stroke of Genius</title>
				<link>http://syntax.wikidot.com/blog:11</link>
				<description>

&lt;p&gt;Everybody knows Alan Turing was the father of the computer. What is less appreciated is that Turing stands right next to Euclid in the pantheon of creative geniuses. What is almost never mentioned is &lt;em&gt;why&lt;/em&gt; Turing deserves so lofty a ranking.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 01 Mar 2009 16:50:35 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Everybody knows Alan Turing was the father of the computer. What is less appreciated is that Turing stands right next to Euclid in the pantheon of creative geniuses. What is almost never mentioned is <em>why</em> Turing deserves so lofty a ranking.</p> <p>I'm an autodidact, so I don't know how the computer science curriculum is usually organized, but I would guess that students learn about Turing machines relatively early in their education, once they have mastered a few programming languages. I've been through a half dozen or so texts on theoretical computer science that cover this ground. They all have one thing in common: <em>they utterly ignore Turing's fundamental insight</em>!</p> <p>Such texts teach the machine; one learns that a Turing machine involves a &quot;tape&quot; that slides about, with a read/write head, etc. So the student memorizes, works exercises, and comes away with a nice, formal notion of computation in terms of an abstract machine. That's the way I learned it, any way, and it seems to be the way most textbooks teach it.</p> <p>Now that's a fine thing, and it explains how computers work, and how some things are &quot;computable&quot; and some not, and so forth. It's all very clever, but it's also entirely <em>formal</em>. I didn't come away from it thinking that Turing was anything but a very clever mathematical engineer. In fact the lambda calculus seems much more elegant and simple than all this business of tapes, machine states, and so forth. Turing seemed to me to be a little like Henry Ford or Thomas Edison: an inventor of a useful machine. An ingenious inventor, but still just an inventor. Studying Turing machines never gave me the feeling that I was in the presence of genius; I would have ranked many mathematicians far ahead of Turing.</p> <p>Then I came across Robert Soare's paper <a href="http://www.people.cs.uchicago.edu/~soare/History/">Computability and Recursion</a> and realized that I was getting only half the story. I'm not competent to judge the paper's technical merits, but I can confidently recommend that it should be required reading for anybody studying either Turing machines or the lambda calculus, if only for its excellent account of the history of the concepts of computability and recursion. It's really more an essay in the history of ideas than a technical paper.</p> <p>The key point Soare makes, although he doesn't express it in quite this way, is this: it's all about <em>intuition</em>, and intuition is all about <em>lived, human experience</em>. The formalism of the machine comes <em>after</em> the leap of imagination that allowed Turing to crystalize intuitions about human experience in formal terms. Soare points out that Godel was unconvinced by Church's recursive model of computation precisely because it was unconnected to intuitions derived from lived experience.</p> <p>It turns out that the key section of Turing's landmark 1936 paper, <em>On computable numbers, with an application to the entscheidungsproblem</em>, is section 9, wherein he grounds his formalism in an attempt &quot;to show that the 'computable' numbers include all numbers which would naturally be regarded as computable&quot;. The next sentence strikes at the heart of the matter: &quot;All arguments which can be given are bound to be, fundamentally, appeals to intuition, and for this reason rather unsatisfactory mathematically.&quot; In other words, we have certain real-world experiences calculating numbers, and based on that experience, we have an intuition that some numbers are just &quot;naturally&quot; computable. Now the previous eight sections of his paper described his Turing machine; his observation here amounts to an admission that there is a fundamental rift between our intuitive notion of naturally computable and the numbers computable by his machine formalism. On the one hand, it's not enough to just have a warm fuzzy feeling that the machine can compute everything we think is naturally computable; on the other hand, we can never <em>prove</em> that it can, since intuitions based on experience are not mathematical objects.</p> <p>Turing's stroke of genius was to do for the experience of calculating what Euclid did for the experience of extensionality in space: he found a way to think about that experience in terms of an ideal, formal imaginative structure whose faithfulness to intuitive experience is indisputable. Euclid came up with notions like a point with no height or width and a line with width but no height; such ideas can never be <em>proven</em> to represent real space, but the intuition that they do is so compelling that it must be accepted. Turing did exactly the same thing for the experience of calculating, literally with pencil and paper.</p> <p>Most of section 9 of his paper is devoted to describing the work of a human &quot;computer&quot;. As Soare points out, in the mid-thirties the term &quot;computer&quot; meant a human engaged in calculation. Turing analyzed the <em>process</em> involved in such calculating. Post-Turing, it's easy to underappreciate what an imaginative leap this was. Calculation by a human, with pencil and paper, is <em>essentially</em> an analog process. If it doesn't look like that to you today, it's only because of the revolution in thought brought about by Turing. (Evidence: Godel couldn't come up with it.) He looked at the process of calculating by writing stuff down on a piece of paper divided into squares &quot;like a child's arithmetic book&quot;, and essentially realized that we can model that analog process as a finite discrete process, a sequence of &quot;'simple operations' which are so elementary that it is not easy to imagine them further divided.&quot; He furthermore realized that we can model the human computer's &quot;state of mind&quot; in finite, discrete terms. With a few other simple constraints we end up with a formal imaginative model of the work of the human computer that can be directly &quot;mathematicalized&quot;; we can &quot;construct a machine to do the work of this computer&quot;, and that machine will correspond naturally, intuitively, and directly to the lived experience of performing a calculation. Turing's machine is to the experience of calculation as Euclid's one dimensional line is to the edge of a straightedge.</p> <p>The sad thing is that section 9, although it is the heart of Turing's argument, is very simple; but I've yet to come across a text on theoretical computer science that even mentions it. You don't really even need mathematics to understand it, and yet it is the foundation of a massive revolution in human thinking. If a number is computable by a Turing machine, and a Turing machine is a formalization of intuition, then what does &quot;number&quot; mean? For Euclid, number was synonymous with length (which is why the Greeks could not stomach zero as a number); post-Turing, (computable) number is synonymous with the process of computation. For Euclid, numbers say something about extension in space; post-Turing, numbers say something about <em>thinking</em> - Turing's machine models the process of human computation; human computation is a thought process; therefore Turing machine is synonymous with mind. Etc. etc.</p> <p>In the popular mind this sort of stuff often comes up as the question of whether or not computers can think, which most people probably think of as whether or not computers can simulate human behavior. But the real question is the other way around: is thinking essentially computational? Not so different from asking whether space is essentially geometric.</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:10</guid>
				<title>Performance Economics</title>
				<link>http://syntax.wikidot.com/blog:10</link>
				<description>

&lt;p&gt;Another cooked-up performance &amp;quot;controversy&amp;quot; is bubbling on the haskell-cafe mailng list: is gcc a &amp;quot;better&amp;quot; compiler than ghc? The question hinges on the performance (speed) characteristics of a relatively small, simple chunk of code when run through the respective compilers. It seems gcc makes faster code in this isolated case. I can&#039;t follow the technical details, but I do know that this kind of &amp;quot;performance&amp;quot; comparison is pointless and probably harmful.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Sat, 21 Feb 2009 12:00:32 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Another cooked-up performance &quot;controversy&quot; is bubbling on the haskell-cafe mailng list: is gcc a &quot;better&quot; compiler than ghc? The question hinges on the performance (speed) characteristics of a relatively small, simple chunk of code when run through the respective compilers. It seems gcc makes faster code in this isolated case. I can't follow the technical details, but I do know that this kind of &quot;performance&quot; comparison is pointless and probably harmful.</p> <p>Such comparisons totally miss the point by misunderstanding the notion of performance. Performance is not about time and/or space efficiency, it's about <em>economic</em> efficiency, and the speed of compiled code is only one factor in the economic equation. Your compiler can produce the fastest code in the world, but it won't be of much use if it isn't <em>correct</em>. So any calculation of return on investment must factor in the &quot;cost of correctness&quot;.</p> <p>Assuming correct code and correct compilation, a compiler that produces faster code offers better Return On Investment. But every programmer knows you cannot make such assumptions, so an investment decision based solely on speed benchmarks is a poor decision based on incomplete information.</p> <p>In any real-world project of even modest complexity this means a performance assessment of a toolset like C++ and gcc must account for all the effort involved in &quot;proving&quot; correctness. Since proof is not possible, this means not only the cost of testing, but also the cost of fixing bugs. Testing can never prove the absence of bugs, so all such code, even when published as production quality, is essentially experimental.</p> <p>Hence functional languages have a major advantage in performance economics, since the cost of correctness drops considerably. We can never prove that a piece of software correctly addresses a customer's problems, or that the problem specification is accurate, but functional languages go a long way towards guaranteeing correctness of the code itself. And if you've proven the correctness of the code, there's not much point in making major investments in testing what needn't be tested. Some testing or validation will always be required - e.g. design of the user experience - but most expense involved in establishing code correctness is incurred up front in the effort it takes to prove correctness. Which in principle should be a lot less than the expense of testing and fixing code written in imperative languages.</p> <p>Moore's law is a law of <em>economics</em>, not a law of nature. Engineering is essentially about economics. I would bet there is a similar law waiting to be discovered about the economics of programming, since functional languages (along with logic languages and some other idioms) promise to turn programming into something resembling real engineering. Haskell code has certain mathematical properties that the equivalent C/C++/Java/etc. code cannot hope to have, which means it can reliably be analyzed and transformed based on mathematically principles rather than heuristics. New methods of optimization are bound to arise that will be unavailable to imperative language compilers.</p> <p>It's inevitable that some day functional language compilers will produce code that even the best hand-rolled assembler cannot match for speed and space efficiency. When that starts to happen and the economics of functional languages - or rather, languages with some kind of support for provable correctness - become more clear, it wouldn't be surprising to see chip designers revive the idea of machines designed for reduction optimization.</p> <p>In any case, the point is that people who want to make the case for Haskell or other functional languages should not allow themselves to be suckered into discussions about performance isolated from other economic factors. Benchmark code should not use simple algorithms whose imperative implementations involve minimal side-effects and can thus be reasoned about informally with little effort. Instead they should involve a well-defined problem, as simple as possible, but one that requires the kind of non-trivial reasoning that complicates the life of an imperative programmer. Something that makes cost of correctness as much a part of the benchmark as space/time efficiency. And such benchmarks should always be called &quot;performance economics benchmarks&quot;, never just &quot;performance benchmarks&quot;.</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:9</guid>
				<title>Intergalactic Telefunctors and Quantum Entanglement</title>
				<link>http://syntax.wikidot.com/blog:9</link>
				<description>

&lt;p&gt;In a previous article I argued against the pernicious Container Fiction. Some respondents have quite reasonably responded that this seems a bit pedantic; it may be true that e.g. a list is not &lt;em&gt;really&lt;/em&gt; a container, but it&#039;s such a useful metaphor that only a pedant would insist on banning it.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 15 Feb 2009 16:06:35 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>In a previous article I argued against the pernicious Container Fiction. Some respondents have quite reasonably responded that this seems a bit pedantic; it may be true that e.g. a list is not <em>really</em> a container, but it's such a useful metaphor that only a pedant would insist on banning it.</p> <p>Indeed it is a very useful metaphor, but the motivation for exposing it as a &quot;pernicious&quot; myth is not linguistic fascism, but rather pedagogical clarity. The Container Fiction is only pernicious insofar as it interferes with a clear understanding of the underlying abstraction it attempts to capture: the functor as a special kind of relation that enables communication between two different and mutually incomprehensible universes. This is bound to happen, since the container fiction is deeply embedded in the world of set theory, and the key to understanding Haskell is category theory, which is a whole nother thing.</p> <p>The list is probably not the best example, since it involves a lot of complexity, what with the free monad and so forth. A simpler example would be a pair (a,b). This can obviously considered a kind of container, but as metaphors go a somewhat less pernicious image is the chemical compound. A chemical compound has different properties than its consituents; carbon monoxide (CO) is quite a different thing than carbon and oxygen. It's not a container of its constituents, it's their compound. The relation of (the denoted value) of &quot;(a,b)&quot; to its &quot;components&quot; a and b is similar. It's a <a href="http://plato.stanford.edu/entries/mereology/">mereological</a> relation, not a containership relation.</p> <p>But even that obscures the true nature of the functor (). The value denoted by &quot;(a,b)&quot; is <em>not</em> a compound, it is a primitive, whole, opaque value. (Disregard for the sake of argument whether it is dependent on the human mind.) The compound is the expression &quot;(a,b)&quot; itself.</p> <p>My proposition is that a category theoretic explanation can be clearer and <em>simpler</em> than such metaphorical expositions, leading to a solid articulated intuition of the structural nature of functors without resorting to colorful metaphors. Well, maybe one, but it's arguably not a metaphor. A full exposition would take some very careful writing and a bunch of diagrams, but here's a sketch of how it would work.</p> <p>Start with a, b, and (). Symbols 'a' and 'b' name things in a home universe; '()' is (the name of) an intergalactic &quot;telefunctor&quot; that relates the home universe to an alien universe of pair values. &quot;(a,b)&quot; takes two primitive values from home to a third primitive value in the alien universe. It doesn't <em>convey</em> a and b to the alien universe; rather, it <em>entangles</em> them. IOW, &quot;(a,b)&quot; is a kind of name or definite description of a value that is just as primitive and indivisible as the value denoted by &quot;a&quot; but that lives in an alien universe. We could say that &quot;(a,b)&quot; represents the <a href="http://en.wikipedia.org/wiki/Quantum_entanglement">quantum entanglement</a> of a and b with the value denoted by &quot;(a,b)&quot;. Call that value x. It lives in an alien universe; we know nothing about its internal structure, nor what it looks like in its universe, nor how it relates to other elements of its universe. But we do know something about how it relates to values in our home universe. We obviously know it is related - via () - to a and b together. But we also know, because of the way we define () - since this is just a brief sketch I omit this definition - we know that x is related to a and b individually. Our definition of () goes with two other definitions: fst (a,b) = a, and snd (a,b) = b.</p> <p>Now we have defined the value of () purely in terms of how it relates things across intergalactic (ok, couldn't resist a metaphor) boundaries - morphisms. We could go further and show how a and b can also be defined as morphisms - after all, they're just names denoting values, and those values are just as opaque and unapproachable as the value of &quot;(a,b)&quot;. Our knowledge of how all these things behave is expressed in terms not of what they <em>are</em>, but in how they <em>relate</em>. You can judge a man by his friends; you can understand mathematical values by their relations to other values.</p> <p>A diagram might represent values as blackened circles. I believe this approach leads to a very clear, simple, and reasonably complete exposition. The metaphor of alien universes and intergalactic telefunctors could of course be dispensed with, but it does add color without introducing semantic distortion.</p> <p>The real virtue of this approach becomes more clear when we complement the above exposition of the object component of a functor with a similar account of the morphism component that takes functions from one realm to functions in the alien realm. The pedagogical payoff is the realization that a functor allows us to use what we know about values in one realm to &quot;manipulate&quot; values in another realm. The best metaphor for the functor is neither containment nor mereology, but <a href="http://en.wikipedia.org/wiki/Quantum_entanglement">quantum entanglement</a>.</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:8</guid>
				<title>In Praise of Elitism</title>
				<link>http://syntax.wikidot.com/blog:8</link>
				<description>

&lt;p&gt;A respondent to one of my earlier posts complained that approaching Haskell by way of category theory is a &amp;quot;radical approach that would lead to elitism&amp;quot;, since such an approach is likely to scare off all but the mathematical sophisticate.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Sun, 15 Feb 2009 12:17:43 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>A respondent to one of my earlier posts complained that approaching Haskell by way of category theory is a &quot;radical approach that would lead to elitism&quot;, since such an approach is likely to scare off all but the mathematical sophisticate.</p> <p>That may or may not be true - in my opinion a well-written CT-oriented intro to Haskell need be no more terrifying than any other - but I take mild exception to the implied assertion that &quot;elite&quot; is somehow bad.</p> <p>The community of Haskell programmers (and functional language programmers in general) is a natural, self-selecting elite. There's nothing wrong with that; on the contrary, the elite status of the Haskell Master should be celebrated. Haskell is hard, there's no sense in denying it, but so are most things worth doing. It's hard to master the piano, or fly-fishing, or brain surgery, or a foreign language, and nobody sensible would pretend otherwise. Why should the highly sophisticated art of functional programming be any different? Elite does not mean snide, or exclusionary, or condescending, or selfish; it means excellence, and the truly elite are open-minded, inclusive, and generous with their hard-earned knowledge.</p> <p>I came to Haskell with years of imperative programming under my belt. I became a pretty &quot;advanced&quot; programmer, but I never really felt like I was doing anything a clever monkey couldn't do. A C programmer spends most of his time doing much what an auto mechanic does - diagnosing and fixing problems in a sophisticated machine. There's nothing wrong with being an auto mechanic or a C programmer; but it's not exactly an elite.</p> <p>On my third try I've finally begun to appreciate the beauties of Haskell. The turning point for me was category theory, which lead to a sea change in my thinking. I'm not sure I'll ever become a master Haskell programmer - one of the great things about it is you can acquire a pretty good understanding of how the language works without writing Haskell programs - but it's clear that those who do master it are a different kind of programmer. Show me a great C programmer and I'll show you a Thomas Edison; show me a great Haskell programmer and I'll show you a J. S. Bach. (Idea for a logo: a measure of musical notation with a lambda clef, and notes tied by arrows.)</p> <p>The message to newcomers should not be &quot;don't worry, it's just like PHP, only different&quot;. It would be more honest to state right up front that this is a different game: entree to the elite is open to anybody, but not for free. You have no right to demand excellence without effort. You have to work; you have to master some mathematical ways of thinking that can in fact be difficult even for those with a good deal of math. You can do this; many others have. But if you're the type to throw a fit the first time you discover that your customary ways of thinking won't work, then please, go away. This is for grown-ups.</p> <p>If you value excellence, and are motivated by the prospect of rising above the common dross and attaining excellence yourself, then you are in for a great intellectual adventure of deep insights and dazzling discoveries. And you will find lots of help. There is a plethora of material on the web that will help you, and the community of those who have gone before you is open and more than willing to help those in their apprenticeship.</p> <p>In my experience the best, most imaginative and talented people are stimulated by a challenge to excel. They <em>want</em> the hard stuff, and they're the ones who should be evangelized.</p> <p>The message to business people should be similar. No, Haskell is not PHP on steroids, it's a different beast altogether. It's a major paradigm shift, with major benefits that are well worth the costs. You hire expensive, highly-trained MBAs to professionally manage your company's financial assets; why would you not hire elite programmers to manage its information assets? The importance of husbanding knowledge assets to gain competitive advantage is only going to increase; treat it as mere data processing and your competitors will eat you alive. Yes, it's harder to find a good Haskell programmer than it is to find 100 mediocre PHP hackers, but aside from being more productive, the Haskell programmer comes with a disciplined, highly sophisticated way of thinking about information structures and algorithms. This makes it much more likely that your Haskell staff will do a much better job of figuring out how to turn your raw data into real capital that returns value.</p> <p>(Fortunately I don't have any money riding on my sales pitch.)</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:7</guid>
				<title>Pernicious Myth No. 1:  The Container Fiction</title>
				<link>http://syntax.wikidot.com/blog:7</link>
				<description>

&lt;p&gt;Newcomers to Haskell quickly learn that lots of containers are involved. Lists and tuples are containers; a monad is like a container; constructed data contain the arguments used in construction, and so forth.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Sat, 14 Feb 2009 15:35:23 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Newcomers to Haskell quickly learn that lots of containers are involved. Lists and tuples are containers; a monad is like a container; constructed data contain the arguments used in construction, and so forth.</p> <p>It's a useful fiction, but it is a fiction. A value of type &quot;[a]&quot; does <em>not</em> contain values of type 'a', or anything else, for that matter. The Container Fiction is pernicious insofar as it retards progress toward a deeper understanding of how the notation works and why category theory provides such a powerful semantic framework.</p> <p>All values are ontologically primitive.</p> <p>This is obvious if you look at &quot;simple&quot; values like integers. Is 3 primitive? Some mathematicians would disagree. The number three, they might argue, is constructed using {} and a successor function. Or they might argue that it's a sequence of lambda expressions of some kind. There are probably lots of other ways to describe the meaning of '3' using various mathematical constructions.</p> <p>These are all just different ways of <em>describing</em> a mathematical object; but as one of my college professors (expert in comparative religion) was fond of saying, map is not territory. Description of an object does not an object make. If these various and sundry descriptions all describe the same thing, then that thing must be independent of the descriptions.</p> <p>Constructive mathematics does not construct its objects, it describes them. It would be the height of hubris to suggest otherwise; after all, numbers do not depend on the exertions of mathematicians for their continued existence.</p> <p>The vitality of the Container Fiction demonstrates the power of the Iconic Fallacy. Values do not contain, but syntactic expressions do. We think that an ordered pair (a,b) contains a and b. It doesn't, but the graphical form, using parentheses, strongly implies that containment is involved. This is the Iconic Fallacy: false inference about the nature of the thing signified drawn from the form of the signifier. An expression like [1,2,3] &quot;looks like&quot; a list of integers; it does not therefore follow that it <em>is</em> (or denotes) a list of integers. It would be more accurate to say it is a construction that <em>uses</em> a list of integers to denote a value. The expression &quot;[1,2,3]&quot; represents application of a morphism (the [] functor) to an argument; if its denoted value contains 1, 2, and 3, then does the denoted value of <span class="math-inline">$\sqrt 4$</span> contain <span class="math-inline">$4$</span>?</p> <p>Part of the problem is that &quot;List&quot; (i.e. []) is misnamed, implying that '[a]' <em>is</em> a list. It's named after the target end of the arrow; a proper name would be something like &quot;TypToList&quot;, thus emphasizing that it is a morphism.</p> <p>This may seem like so much philosophical splitting of hairs, but it's not. On the contrary, it correlates with one of the fundamental insights of category theory, namely, elements don't matter. I believe it's very important for learners of Haskell (or any FPL with lazy evaluation) not only to learn to think in terms of mathematics, but also to learn to think about how mathematical notation works. I speak from experience; when I first picked up Haskell I used a book that insisted that something like &quot;x = Foo 1 (2,3) 'a'&quot; means that x contains 1, and (2,3), and 'a'. That didn't match up with the ideas I had formed about algebraic data types, so I eventually ended up dropping the whole thing in exasperation.</p> <p>More specifically: it's important (essential?) to realize that we can only talk about values indirectly. On the one hand that means we have to use a language with syntax, obviously. But it's deeper than that. We can only talk about mathematical objects by &quot;triangulating&quot; using other, related mathematical objects. As a concrete example consider an ordered pair (1,2). Disregarding syntax, lambda expressions, etc., the value (1,2) is a primitive object that is the image of 1, 2 under the mapping ( ). The only way we can talk about it is to use these three things. Not the &quot;contents&quot; of (1,2) - it has no contents - but the things we used to construct (describe) it , which are completely distinct from the thing itself.</p> <p>The most important reason to learn to think like this is that it is the primary idiom of category theory. For example, in CT terms, something like (1,2) is treated as an opaque object together with two projection arrows fst and snd. No contents involved, just an object and two mappings. The internal structure of the object is irrelevant. Saunders MacLane says somewhere that CT is about &quot;learning to live without elements&quot;; applied to Haskell, that means learning to live without containers.</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:6</guid>
				<title>Fixing Haskell IO</title>
				<link>http://syntax.wikidot.com/blog:6</link>
				<description>

&lt;p&gt;No, Haskell IO isn&#039;t broken; that&#039;s just a shameless bid for attention. But the metalanguage commonly used to describe Haskell IO &lt;em&gt;is&lt;/em&gt; broken.&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Fri, 13 Feb 2009 17:26:34 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>No, Haskell IO isn't broken; that's just a shameless bid for attention. But the metalanguage commonly used to describe Haskell IO <em>is</em> broken.</p> <p>Here are a few typical examples of how IO in Haskell is described:</p> <blockquote> <p>A value of type IO a is an “action” that, when performed, may do some input/output, before delivering a value of type a. (<a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/marktoberdorf/">Tackling the awkward squad: monadic input/output, concurrency, exceptions, and foreign-language calls in Haskell</a>, p. 5)</p> </blockquote> <blockquote> <p>a type IO a denoting actions that when performed may do some IO and then return a value of type a. (<a href="http://homepages.inf.ed.ac.uk/wadler/papers/imperative/imperative.ps">Imperative Functional Programming</a>, p. 3)</p> </blockquote> <blockquote> <p>The key idea is to treat a value of type IO a as a “computation” that, when performed, might perform input and output before delivering a value of type a. (<a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/history-of-haskell/index.htm">A History of Haskell: Being Lazy With Class</a>, p. 25):</p> </blockquote> <p>We can summarize the SDIOH (Standard Definition of IO in Haskell) as &quot;a value of type IO a is a value, that performs, then delivers a value of type a&quot;.</p> <p>Now consider how one might describe a run-of-the-mill non-IO value: &quot;a value of type T a is &#8230; a value of type T a&quot;. All definitions are tautologies. By definition. If the SDIOH is a true definition, then IO values are not like other values, and we have a two classes of value in Haskell. If it is not a tautology, then it is not a definition, and we still don't know what an IO value is.</p> <p>Since it is clearly undesirable to have two different kinds of value, it must be that the SDIOH is in fact not a definition. Then what is an IO value?</p> <p>Part of the problem with the SDIOH is its use of ambiguous terms. It's impossible to discern exactly what it means by &quot;value&quot; and &quot;computation&quot;. But that's only part of the problem. The deeper problem, which is related to the terminological problem, is that the semantic model (for lack of a better term) behind the SDIOH adopts a particular perspective on the semantic operations involved in evaluation that forces us to mix being and doing.</p> <p>The current idiom portrays an IO value as an agent that dynamically performs some kind of action. The GHC implementation of IO operators express this concretely by modeling IO as a state transformer that acts on the RealWorld. This &quot;works&quot; well enough; GHC manages to perform IO. But it doesn't fly mathematically. Mathematical objects <em>never</em> act, sing, dance, or <em>do</em> anything. They just are. A value that acts is an oxymoron.</p> <p>Fixing this requires a shift in perspective and a more refined elaboration of the mental model we use to think about IO in Haskell. The trick is to reverse the perspective. Instead of viewing the program as an agent that acts on the world, we view the world as an agent that provides an interpretation for program. We refine the model by dividing semantics into two parts: internal semantics encompass the mapping from Haskell expressions to lambda expressions, along with lambda conversion of expressions; the external semantics cover the assignment of an interpretation to the lambda expressions.</p> <p>For example, we can account for the semantics of '3' as follows: the internal mapping takes the Haskell expression '3' to the lambda expression '_3' (using prefixed _ to mark symbols in the metalanguage). The World in turn <em>interprets</em> the program text, mapping '_3' to the integer of that value. If we wish we can define a World metalanguage. Using a Haskell-like syntax, we say '_3' is interpreted as &quot;Z 3&quot; of type &quot;W Z Int&quot;.</p> <p>This gives us a clear, simple account of the semantics of IO values without any notion of action. An IO a value is just an IO a value; no different than any other kind of value. Semantics comes from interpretation. The internal semantics map non-IO expressions to <em>constant</em> (bound) lambda expressions. To account for IO expressions, we use lambda <em>variables</em>. For example, &quot;getChar&quot; maps to something like $v : IO Char$ (assuming our metalanguage uses : to indicate type). In other words, the internal semantics takes an IO expression to a free variable in the metalanguage. Now free variables range over all values of their type; so the World's interpretation of such a free variable is the set of mappings from the variable to the World values of the World type corresponding to the argument of the IO type (the 'a' in IO 'a'). In other worlds, the set of all possible bindings of $v : IO Char$ to World values of type &quot;World Char&quot;; for getChar, something like &quot;Char 'c'&quot;.</p> <p>The meaning of the program then becomes the set of all possible World interpretations of it. The notion of actors and actions has been completely eliminated. The notion of &quot;value of type IO a&quot; has been replaced by a description of the way IO expressions are interpreted. The SDIOH is replaced by something like:</p> <blockquote> <p>An expression of type IO a is bound to a free variable in the metalanguage, which is bound to a (World) value of type a in each interpretation of the program</p> </blockquote> <p>Naturally, for this to work we would need to rework other parts of the metalanguage, and we would want to come up with some kind of metalanguage for referring to World types and values. In particular, we need to complement the definition of IO values with a definition of (non-IO) values:</p> <blockquote> <p>a expression of type T a is bound to an expression in the metalanguage that contains no free variables &#8230;</p> </blockquote> <p>This definition would have to be refined, but the basic idea is to distinguish between lambda expressions whose Head Normal Forms have a constant binding to World values, and those that are free.</p> <ul> <li>the role of the lambda calculus as a metalanguage is made explicit</li> <li>IO expressions bind to free vars in the lambda metalanguage</li> <li>a World metalanguage provides a model for interpretations</li> <li>Executing a program means having the World give it an interpretation</li> </ul> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:5</guid>
				<title>&quot;Computation&quot; considered harmful. &quot;Value&quot; not so hot either.</title>
				<link>http://syntax.wikidot.com/blog:5</link>
				<description>

&lt;p&gt;The term &amp;quot;computation&amp;quot; has at least six different senses, all of which are commonly used in technical literature:&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Fri, 13 Feb 2009 15:50:29 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>The term &quot;computation&quot; has at least six different senses, all of which are commonly used in technical literature:</p> <ul> <li>a dynamic computing process</li> <li>the result of a computational process</li> <li>an algorithm that describes a computational process</li> <li>a formal description of an algorithm in a specific language</li> <li>a formal description of the semantics of a computational process; e.g. a lambda expression</li> <li>a dynamic process that converts a lambda expression to normal form</li> <li>a formal description of lambda conversion</li> </ul> <p>One could probably come up with additional technical uses for the term. Even worse, &quot;computation&quot; is an ordinary word with well-understood if inexact semantics. Readers come to a technical text with a well-formed idea of what the word means, and thus no reason to think their notion is incorrect.</p> <p>&quot;Value&quot; is even worse. It too carries multiple technical meanings in the literature, and it is even more common in ordinary language. Same for &quot;evaluation&quot;.</p> <p>These terms are ambiguous. They should be banned from technical discourse.</p> <p>Usually this ambiguity is tolerable, at least for subject matter experts. But when it becomes a problem, it's a big problem. It cost me many exasperating hours of head-scratching when I decided to finally get to the bottom of monads and IO in Haskell.</p> <p>The texts that flummoxed me are Moggi's paper on &quot;notions of computation&quot; and the standard idiom used to describe IO in Haskell.</p> <p>Moggi (<a href="http://www.disi.unige.it/person/MoggiE/ftp/ic91.pdf">Notions of computation and monads</a>, p. 3):</p> <blockquote> <p>In particular, we identify the type A with the object of values (of type A) and obtain the object of computations (of type A) by applying an unary type-constructor T to A. We call T a notion of computation , since it abstracts away from the type of values computations may produce.</p> </blockquote> <p>A typical example of how IO is described in Haskell (<a href="http://research.microsoft.com/en-us/um/people/simonpj/papers/history-of-haskell/index.htm">A History of Haskell: Being Lazy With Class</a>, p. 25):</p> <blockquote> <p>The key idea is to treat a value of type IO a as a “computation” that, when performed, might perform input and output before delivering a value of type a.</p> </blockquote> <p>Obviously this language is &quot;good enough&quot;, since Moggi's paper was very influential, and Haskell is very successful. But both passages immediately struck me as hazy and somewhat absurd. Try as I might, I could find no way to assign a precise meaning to them. It took a lot of research and a flurry of messages on the haskell-cafe mailing list to figure out why they didn't work for me and discover what the authors (probably) meant.</p> <p>Needless to say, part of the problem was the ambiguity of the terms &quot;computation&quot; and &quot;value&quot;. I came to the texts thinking that a value is either a &quot;datum&quot; like 3 or a function like sqrt. They're just static mathematical objects, so I could not conceive of how a value could &quot;be&quot; a computation, or could &quot;be performed&quot;.</p> <p>The scales fell from my eyes when I came across the following passage buried in the Wikipedia article on <a href="http://en.wikipedia.org/wiki/Theory_of_computation">Theory of Computation</a>:</p> <blockquote> <p>A computation consists of an initial lambda expression (or two if you want to separate the function and its input) plus a finite sequence of lambda terms, each deduced from the preceding term by one application of Beta reduction.</p> </blockquote> <p>I was already familiar with the lambda calculus, but I had never thought of a lambda expression as a &quot;computation&quot;. I still don't like it; a lambda expression is not a computation, it's a formal <em>representation</em> of a mathematical object (a <em>value</em>). Lambda conversion is a purely syntactic calculation that yields a different notational representation of the same value. The lambda calculus is a <em>formal model</em> of computation; the same computation could be represented in a different formalism. So it's just wrong to say that a computation <em>is</em> a sequence of lambda expressions.</p> <p>Nonetheless, it's clear why one might think in these terms and use this language, and I think that is what's going on in the passages quoted above. My ideas of computation and value were based on the idea of a direct mapping from expression to mathematical object. Even though I was quite familiar the notions of language and metalanguage, I thought of a metalanguage as serving mainly to clarify meaning; once you understand the semantics of the language, you can disregard the metalanguage and think directly in terms of abstract semantic objects (e.g. numbers and functions.)</p> <p>But in Haskell that's not good enough; to understand how lazy evaluation works, you need to keep lambda calculus (or the equivalent) in mind, because denotation has to pass through lambda expressions in various states of reduction before arriving at normal form and then semantic objects. You cannot disregard the lambda metalanguage, because the different forms lambda expressions may take constitute part of the semantic universe. Make it explicit and things become more clear. The above definition of Haskell IO becomes:</p> <blockquote> <p>The key idea is to treat a value of type IO a as a “lambda expression” that, when converted to normal form, might perform input and output before delivering a value of type a.</p> </blockquote> <p>Unfortunately, that's not good enough: how can a lambda expression in normal form &quot;be performed&quot; and &quot;deliver&quot; a value?</p> <p>That is the subject of my next post, wherein I will discuss weaknesses in Haskell's informal metalanguage and suggest replacements for &quot;computation&quot;, &quot;value&quot;, and &quot;evaluation&quot;.</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:4</guid>
				<title>Programming Language Semiotics</title>
				<link>http://syntax.wikidot.com/blog:4</link>
				<description>

&lt;p&gt;In a recent &lt;a href=&quot;http://www.haskell.org/pipermail/haskell-cafe/2009-February/055421.html&quot;&gt;posting&lt;/a&gt; to the haskell-cafe mailing list, Richard O&#039;Keefe put his finger on a major problem that afflicts most if not all expositions of Haskell&#039;s evaluation semantics with respect to IO operations:&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Tue, 10 Feb 2009 13:20:28 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>In a recent <a href="http://www.haskell.org/pipermail/haskell-cafe/2009-February/055421.html">posting</a> to the haskell-cafe mailing list, Richard O'Keefe put his finger on a major problem that afflicts most if not all expositions of Haskell's evaluation semantics with respect to IO operations:</p> <blockquote> <p>We need some standard terminology to distinguish between *evaluating* an expression and *performing* the result of an expression of type IO something.</p> </blockquote> <p>This is a specific example of a more general problem with the standard idioms of programming language semantics. Traditional mathematical approaches - denotational, operational, algebraic, etc. - have one thing in common: they are purely &quot;dyadic&quot;, to borrow a term of art from semiotics. They are founded on binary oppositions like language v. semantic domain, term v. denotation. But program texts resist such narrowly focussed conceptualizations. They have too many layers or dimensions of meaning. Terms like &quot;evaluation&quot; tend to be ambiguous, since they are so general.</p> <p>Consider something as simple as the constant '3'. It's a symbol; it denotes a well-known, cleanly delimited value. But it also &quot;means&quot; a bit pattern in memory (its physical representation); that bit pattern in turn may have multiple meanings. It may be an opcode that &quot;means&quot; addition or some other operation on the architecture. It may be an opcode with a different meaning on another machine. It may have a different meaning for various peripheral interfaces. More importantly, it has a meaning for the author of the text. It may be used with its &quot;standard&quot; (i.e. mathematical) meaning, but it also may be used as an element of some kind of code; it may mean &quot;status complete&quot; or &quot;account suspended&quot; or anything else. It may mean '7', if the author is a perverse obfuscator.</p> <p>With IO terms the situation is even more complicated. A term like &quot;putChar 'c'&quot;, as Richard pointed out, is associated with at least two things: a &quot;value&quot; (meaning, I believe, something like closure/suspension/thunk), and an event ('a' appears on the user's screen), corresponding to evaluation and performance, respectively, to use Richard's terminology.</p> <p>The fundamental problem is that the meaning of a program text involves at least three elements, not just two; it always involves an interpreter (the author, reader, execution environment, or other) in addition to the text and its denotation. In other words, we should think of programs not as dyadic denotational systems, but as communication systems involving multiple players and relations. A program is not just a denotational text; it is a sign.</p> <p>Semiotics is usually defined as the study of signs, signification, communication systems, and the like. Regardless of its academic status, it provides a rich stock of concepts and terminology that should be useful for both the formal and informal descriptions of programming language meanings (I almost wrote &quot;semantics&quot;). In particular, its elaboration of concepts like &quot;expression&quot;, &quot;sign&quot;, &quot;denotation&quot; and the like is highly sophisticated, and accommodates the communicative aspect of such terms that a &quot;programming semantics&quot; approach has trouble capturing. A sign involves not just the signifier and signified, but also an &quot;interpretant&quot; (meaning the idea the interpreter forms about the signified, if I'm not mistaken), a code, and various other elements. It covers just about every thing a semantics approach covers - extension, intension, expression, etc. - but from a different and valuable perspective. For semiotics, a semantic system is only one component of a larger system of meaning(s).</p> <p>For a simple example, we can use it to make a distinction between terms like '3' and terms like &quot;putChar 'a'&quot;. The former has a stable, conventional denotation; that makes it a symbol in Pierce's terminology. The latter is not a symbol by this definition; it would more appropriately be called a sign, or maybe an example of a particular sign class. We could elaborate further by describing the &quot;codes&quot; that construct the meanings of symbols and signs. In an exposition that defines its terminology using the language of semiotics, such distinctions may turn out to help avoid the ambiguities and code-shifts common to traditional semantics-based expositions. I can't yet say for sure, but it seems like a promising approach. It even seems possible that formal modeling (as opposed to notation and exposition) might find useful structuring devices in semiotics.</p> <p>To sum up, semiotics might provide a clear, structured way to talk about the many elements and relations involved in the &quot;meaning&quot; of a program text, with a discipline that traditional approaches often lack.</p> <p>A web search on &quot;semiotics&quot; will find many lexicons, tutorials, etc.</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:3</guid>
				<title>Formal semantics for side effects</title>
				<link>http://syntax.wikidot.com/blog:3</link>
				<description>

&lt;p&gt;Got an idea for formal semantics for operations with side-effects like IO operations, random, etc. It&#039;s inspired by Haskell&#039;s use of Category Theory as a semantic device and by the Z specification language (the &lt;a href=&quot;http://www.iso.ch/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=21573&quot;&gt;ISO Standard&lt;/a&gt; is downloadable; see the small print below the price list. An outdated but still useful manual is &lt;a href=&quot;http://spivey.oriel.ox.ac.uk/mike/zrm/&quot;&gt;here&lt;/a&gt;.)&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Mon, 09 Feb 2009 15:56:51 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>Got an idea for formal semantics for operations with side-effects like IO operations, random, etc. It's inspired by Haskell's use of Category Theory as a semantic device and by the Z specification language (the <a href="http://www.iso.ch/iso/iso_catalogue/catalogue_tc/catalogue_detail.htm?csnumber=21573">ISO Standard</a> is downloadable; see the small print below the price list. An outdated but still useful manual is <a href="http://spivey.oriel.ox.ac.uk/mike/zrm/">here</a>.)</p> <p>The idea in brief is that we model the world as a category W, whose objects are events and whose sole arrow is a precedence operator ( &gt;- , \succ in LaTeX). What the events represent specifically is irrelevant; we only care about an event &quot;input 'c'&quot; as an abstract event. Think of this as the infinite list of events that contains all possible permutations of real world events.</p> <p>To provide the semantics of the execution of a program P, we establish an isomorphism between it and W. The isomorphism maps &quot;opaque&quot; terms (e.g. IO terms, random values, etc.) to events. Ordering is preserved by some kind of rule mapping textual precedence in P to event precedence in W. In other words, to model a particular execution of P we incorporate a subset of W into the semantic domain. The static semantics of P are expressed only in the semantic domain, excluding W.</p> <p>Now the meaning of the program is the text of P, its mapping to a semantic domain (the usual denotational mapping for e.g. '3'), plus the set of all possible isomorphisms between opaque terms and W. The actual exposition is a little more complicated than that, but this conveys the general idea.</p> <p>This allows us to express program semantics, including dynamic semantics, in a rigorous, formal model that completely excludes any hint of dynamics, contingency, side-effects, etc. The notion of evaluation is also eliminated.</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://syntax.wikidot.com/blog:1</guid>
				<title>Moggi :: CT -&gt; Hask</title>
				<link>http://syntax.wikidot.com/blog:1</link>
				<description>

&lt;p&gt;The monad found its way into Haskell from &lt;a href=&quot;http://www.disi.unige.it/person/MoggiE/&quot;&gt;E. Moggi&lt;/a&gt;’s research in the late 1980s integrating Category Theory into the domain of programming language semantics. He began by observing that there are three common approaches to proving equivalence of programs:&lt;/p&gt;
&lt;p&gt;by &lt;span class=&quot;printuser avatarhover&quot;&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;&lt;img class=&quot;small&quot; src=&quot;http://www.wikidot.com/avatar.php?userid=21583&amp;amp;amp;size=small&amp;amp;amp;timestamp=1773348133&quot; alt=&quot;gar&quot; style=&quot;background-image:url(http://www.wikidot.com/userkarma.php?u=21583)&quot; /&gt;&lt;/a&gt;&lt;a href=&quot;http://www.wikidot.com/user:info/gar&quot;  &gt;gar&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;
</description>
				<pubDate>Sat, 07 Feb 2009 16:29:36 +0000</pubDate>
												<content:encoded>
					<![CDATA[
						 <p>The monad found its way into Haskell from <a href="http://www.disi.unige.it/person/MoggiE/">E. Moggi</a>’s research in the late 1980s integrating Category Theory into the domain of programming language semantics. He began by observing that there are three common approaches to proving equivalence of programs:</p> <ul> <li>Operational semantics</li> <li>Denotational semantics</li> <li>Model theoretic semantics</li> </ul> <p>All such methods attempt to bridge the syntax/semantics divide. They differ chiefly in the formalisms they adopt to represent the semantic domain, with attendant differences in the syntax-to-semantics mapping. Moggi’s innovation was to use Category Theory to represent the semantic domain. His motivation was the observation that the conventional denotational approach, which identifies type <span class="math-inline">$\alpha \rightarrow \beta$</span> with a total function of the same signature, “wipes out completely behaviours like non-termination, non-determinism or side-effects, that can be exhibited by real programs.” The key word being &quot;behaviors&quot;; a direct mathematical mapping from terms in a language to objects in a semantic domain has no way of accounting for the <em>behavior</em> of terms like “print”, which trigger observable external behavior. Whatever mathematical semantics such terms may have, they also carry additional meaning that cannot be captured by a straightforward denotational representation.</p> <p>The key term he uses is <em>notion of computation</em>:</p> <blockquote> <p>&#8230;in order to interpret a programming language in a category C , we distinguish the object A of values (of type A) from the object T A of computations (of type A), and take as denotations of programs (of type A) the elements of T A. In particular, we identify the type A with the object of values (of type A) and obtain the object of computations (of type A) by applying an unary type-constructor T to A. We call T a notion of computation, since it abstracts away from the type of values computations may produce. There are many choices for T A corresponding to different notions of computations.(<a href="http://www.disi.unige.it/person/MoggiE/ftp/ic91.pdf">Notions of Computation and Monads</a>)</p> </blockquote> <p>He gives the following examples of &quot;notion of computation&quot;: partiality, non-determinism, side-effects, exceptions, continuations, and interactive input/output. What these &quot;notions&quot; have in common is disruption of the semantic integrity of a program text. They violate the principle of referential transparency, rendering the text literally uninterpretable to the human reader. So &quot;notions of computation&quot; effectively means the class of opaque terms in programming languages.</p> <p>In ordinary mathematical notation, as for any formal notation intended for human readers, there are no such opaque terms. There may be terms that are unfamiliar to the reader, but these are unknown, not opaque. They have definite denotation, whereas opaque terms only acquire a denotation when the program is executed as a process on a computing machine. Their semantics are contingent, in contrast to terms like &quot;2 + 3&quot;, which have necessary semantics.</p> <p>This appears to be an insurmountable and lethal problem for the formal semantics of functional programming languages. One goal for the development of functional languages is the elimination of process considerations from the semantics of the language. It should be possible to reason about the meaning of a program text without reference to the process associated with it at run-time. If the language includes opaque terms whose semantics are contingent on the process, then how can it be possible to eliminate processing logic from the semantics? How could one ever hope to prove two programs equivalent?</p> <p>Moggi simply restated the problem with a different focus: opaque, contingent terms may be unknowns, but they are known unknowns. We know who and where they are in a text, so instead of asking how we can reason about them, we ask how we can represent and manage them in such a way that the semantic integrity of the text as a whole is retained. We know they denote, but we don't know their denotations; we know they behave, but since formal semantics is atemporal, we don't know the order in which they will acquire their behaviors. So the problem is twofold: we must find a way to represent them as ordinary mathematical values, and can we must find a way to ensure that their behavior is properly disciplined.</p> <p>Moggi's brilliant solution was to use the strong typing of Category Theory as a representational device, and to use the monad as an organizing device. Categories are strongly typed; they provide us with a means to both represent and sequester opaque terms and their contingent values. Sequestration follows naturally from type discipline: objects of a category representing opaque terms with their contingent values cannot naturally mix with objects of any other category. Since they are ordinary objects, they are integrated into the formal semantics of the language as a whole. Functors are the means by which we &quot;construct&quot; such objects; The fact that they serve as proxies for behaviors does not disrupt this integration; they remain objects. In Moggi's formulation, it is the functor that encodes the notion of computation, each constructed object representing a different notion. This is a clever construction of functor as a mathematical operation with side effects, but it is indisputably a mere metaphor for expository purposes. Functors don't have side effects, but that need not stop us from using them to model executable operations that do.</p> <p>Behavioral discipline follows from the structural properties of the monad. The Kleisli star of category theory and its Haskell counterpart <tt>&#187;=</tt> use data dependency to impose an ordering on their arguments. The semantics of the program text remain atemporal, but when the text is represented as a process, the data dependency will ensure proper ordering of behaviors.</p> <p>If the language of categories and functors makes you queasy, here is how Wadler et al. used Moggi's insights to engineer a solution in Haskell. The Haskell equivalents to category and functor are the type and type constructor. A type T A is the image of type A under the mapping of the functor T. What Moggi called notions of computation, and I have called opaque terms and their associated contingent denotations, others have called variously actions, computations, processes, programs, and so forth. Whatever we choose to call them, Haskell represents them as values of a constructed type - IO a and so forth. Haskell's strong typing serves to sequester them in their type, unable to interact with values of other types. They are first-class values in the semantic model of Haskell, with no side-effects within the language. At run-time, they may have observable behaviors; the Haskell bind operator &#187;=, which implements the Kleisli star of CT, imposes an evaluation order on its arguments.</p> <p>This use of category theory is an absolutely dazzling manoever. A very distinctive feature of category theory is that it erases the distinction between things and relations; &quot;it is technically possible to dispense altogether with the objects and work only with arrows,&quot; in the words of its co-inventor Saunders Mac Lane. And thus it is possible to do this with &quot;notions of computation&quot;: we can disregard them. The fact that, for example, values of type IO a have some kind of observable side-effect at run-time is irrelevant to the formal semantics of the language. Since they are represented as objects in purely categorical terms, using functors and natural transformations, we can dispense with them and transfer our attention to the morphisms - constructors, bind, etc. In other words, we can think of these things not as values (with additional behavior) but as a nexus of relationships encoded as arrows. So when asked, what is a value of type IO, we can justly respond with an imperious: &quot;Faugh! It means nothing to me! But if <em>you</em> must know, go run the program!&quot;</p> <p>- Gregg Reynolds</p> <p>by <span class="printuser avatarhover"><a href="http://www.wikidot.com/user:info/gar" ><img class="small" src="http://www.wikidot.com/avatar.php?userid=21583&amp;amp;size=small&amp;amp;timestamp=1773348133" alt="gar" style="background-image:url(http://www.wikidot.com/userkarma.php?u=21583)" /></a><a href="http://www.wikidot.com/user:info/gar" >gar</a></span></p> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>