<?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>Awelon Blue</title>
	<atom:link href="https://awelonblue.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>https://awelonblue.wordpress.com</link>
	<description>Thoughts on Programming Language Design</description>
	<lastBuildDate>Thu, 23 Feb 2012 22:09:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='awelonblue.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>https://s-ssl.wordpress.com/i/buttonw-com.png</url>
		<title>Awelon Blue</title>
		<link>https://awelonblue.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="https://awelonblue.wordpress.com/osd.xml" title="Awelon Blue" />
	<atom:link rel='hub' href='https://awelonblue.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Declarative State</title>
		<link>https://awelonblue.wordpress.com/2012/02/16/declarative-state/</link>
		<comments>https://awelonblue.wordpress.com/2012/02/16/declarative-state/#comments</comments>
		<pubDate>Fri, 17 Feb 2012 05:29:31 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Language Design]]></category>
		<category><![CDATA[Reactive Demand Programming]]></category>
		<category><![CDATA[State]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=672</guid>
		<description><![CDATA[State models favored for imperative programming, such as mutable references, are unsuitable for declarative programming models including Reactive Demand Programming (RDP). Declarative state is not difficult or complicated, but it is different and might require its own eureka moment. The &#8230; <a href="https://awelonblue.wordpress.com/2012/02/16/declarative-state/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=672&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>State models favored for imperative programming, such as mutable references, are unsuitable for declarative programming models including Reactive Demand Programming (RDP). Declarative state is not difficult or complicated, but it is different and might require its own <a href="http://en.wikipedia.org/wiki/Aha!_effect">eureka moment</a>.</p>
<p>The general scenario is that we are manipulating state by use of declarations.</p>
<p>As <a href="http://awelonblue.wordpress.com/2012/01/12/defining-declarative/">discussed in a previous article</a>, declarations are statements that may hold over a period of time, and may overlap in time. (Contrast events, which hold only for an instant.) Declarations that hold at any given instant must be commutative and idempotent. (Contrast events, generally processed in some order and may be counted.) </p>
<p>To help elucidate some of the constraints on declarative state, I break the general scenario into four quadrants on two axes &#8211; exclusive vs. concurrent writers, and discrete vs. continuous time. </p>
<h3>Exclusive Writer, Discrete Time</h3>
<p>By <i>exclusive writer</i>, I mean there is at most one declaration for how to write state. And <i>discrete time</i> means that there is a well defined `next` time that is distinct from the `current` time. </p>
<p>This is the easy case. </p>
<p>There is no risk of write conflicts. There is no risk of semantic confusion with regards to duplicate writes. The functions for manipulating state are simple &#8211; we just declare the next state to be a function of the current state and other observations the writer might have made. Example declarations might be `<code>next = curr + 2</code>` or `<code>next = curr * 3</code>`. </p>
<p>There will also be some default `idle` behavior for state &#8211; most likely `<code>next = curr</code>` or `<code>next = 0</code>`; the idle behavior will apply if there is no other declaration. (The auto-zero behavior would have some nice properties with regards to garbage collection.)</p>
<h3>Concurrent Writers, Discrete Time</h3>
<p>Concurrent writers introduce two challenges relative to the exclusive writers model: write declarations conflict, and instability from idempotence.</p>
<p><i>Write Declarations Conflict</i></p>
<p>Taking the earlier example, we might see BOTH declarations &#8211; `<code>next = curr + 2</code>` and `<code>next = curr * 3</code>` &#8211; at the same time. These proposed operations clearly do not commute &#8211; i.e. (curr+2)*3 is always 4 points different from (curr*3)+2. So we can&#8217;t just apply them in an arbitrary order.</p>
<p>Fortunately, we don&#8217;t actually need the <i>operations</i> to commute. For declarative definition, we need the <i>declarations</i> to commute. </p>
<p>Essentially, at any given instant we have a <i>set</i> of declarations from all attempting to influence the shared state resource. This set is gathered from all writers, local and distributed. This set will ultimately be represented in some ordered manner in physical memory, but the next state must not depend on that ordering nor on any properties that might have influenced it (such as race conditions, origin, position in source code).</p>
<p>So long as we obey that restriction, we have a lot of freedom on how to resolve conflicts. A few valid options include:</p>
<ol>
<li>Report a `write conflict` and perform the idle behavior. Push the burden of avoiding concurrent operations back on the developers.</li>
<li>Choose one operation to win based on some arbitrary condition that is NOT related to ordering in the set. For example, execute both then choose whatever option results in the smaller value.</li>
<li>Apply a true-random selection. This, perhaps counter to intuition, is valid because the <i>cause</i> of the ordering is independent of the declarations. Though, I&#8217;d disfavor this option because it unnecessarily introduces indeterminism.</li>
</ol>
<p>So the write conflicts aren&#8217;t avoided. Rather, they&#8217;re <i>resolved</i> in some arbitrary manner. </p>
<p>While such resolution is sufficient to respect the declarative definition, the arbitrariness does seem&#8230; unsatisfactory, inelegant. </p>
<p>But declarative definition has nothing to say on the elegance of state models. The job of finding `collaborative` state models that effectively support concurrent writers is ultimately up to language and framework designers. </p>
<p><i>Instability from Idempotence</i></p>
<p>Consider two independent declarations: `<code>next = curr + 2</code>` and `<code>next = curr + 5</code>`. Additions do commute, so if we applied both the result would be curr+7. So it seems okay to apply both demands in an arbitrary order. This would be even more `obvious` if operations on state were restricted to additions, so we&#8217;re just looking at declarations of the form `+2` and `+5` (once we&#8217;ve isolated it to a particular state resource).</p>
<p>Since the writers are <i>independent</i>, they do not know exactly what the other writers are doing. The writer of the `+2` declaration might observe that state is actually increasing 7 points each round, but does not know why. There are many possible scenarios resulting in that observable outcome: {+2,+5} or {+2,+1,+4}, or {+2,+3,+4,-2}. Or even {+2,+2,+5} due to idempotence (which eliminates duplicates).</p>
<p>Now for a change: a writer of a +2 declaration changes it to a +3 declaration. What happens? Well, depending on the initial scenario, the increment per round might change by -2, 0, +1, or +3.</p>
<p>Due to circumstances outside local control, a small change in the declaration of one writer might cause a wide variety of changes in state. For developers, day to day, this is not fun. It is chaotic, unstable, frustrating. </p>
<p>So, how do we achieve <a href="http://awelonblue.wordpress.com/2011/09/04/stability-and-rdp/">stability</a>?</p>
<p>Well, the problem was caused because the declarations were directly additive. +1 and +3 added to +4. +2 and +2 added to +2, due to idempotence. What we need is a state model that becomes <i>more</i> stable as the concurrent writers are closer to agreement &#8211; additive won&#8217;t work.</p>
<p>We could try <i>averaging</i> the values. But consider a scenario such as {+1,+1,+1,+5}. We want this to `average` to +2, but it would actually average to +3 since the +1 only counts once (due to idempotence). So, while this is better, it is insufficient to avoid the problem.  </p>
<p>It turns out that we simply cannot treat writers the same as declarations. </p>
<p>When we need to count writers &#8211; e.g. to model a vote, or a set of independent forces &#8211; then we must make it more explicit by providing an identifier for the writer as part of each declaration. For example, instead of {+2,+2,+5} the scenario becomes {(w1,+2),(w2,+2),(w3,+5)} where w1, w2, and w3 are values (perhaps URLs or GUIDs) identifying distinct writers. </p>
<p>Otherwise, we can use simple mechanisms that do not depend on the number of writers. For example, I might favor simply selecting the smallest value, so {+2,+2,+5} reduces to +2. </p>
<p>Again, this sort of arbitrary choice seems inelegant and unsatisfactory. But if we want more elegant options, we&#8217;ll need state models where the declarations contributing to the future state are actually idempotent, so that we may combine them easily. </p>
<h3>Exclusive Writer, Continuous Time</h3>
<p>The discrete time assumption simplified many things &#8211; state is constant in each `instant` and there is a clear `next` instant that serves as the trigger for updates. Continuous time introduces new possibilities, such as continuous varying state (useful for physics simulations). But it also introduces many challenges. </p>
<p><i>Discrete State with Continuous Time</i></p>
<p>While discrete-varying state models can be used with continuous time, the lack of a `next` instant (or, rather, the infinite abundance of `next` instants) hinders certain expression. </p>
<p>Consider a declaration such as `<code>next = curr + 2</code>`, held for even one millisecond. What would that mean? Do we increment once? Do we increment a billion times because there are a billion picoseconds in a millisecond? Do we increment infinity times? None of those options makes sense. </p>
<p>Without use of `next`, we can still use discrete state in continuous time. However, the writer must describe a fixpoint computation. Conceptually, the declaration is applied an infinite number of times before even one picosecond has passed, and so we must have fixpoint convergence. (Note that idempotent updates qualify trivially as fixpoints.)</p>
<p>We can model many things with fixpoint state models. But it is difficult to <i>prove</i> that the fixpoint of arbitrary functions will converge. And the lack of expressiveness is frustrating. And design patterns to work around problems (i.e. using delayed writes to incrementally modify state) tend to be onerous and unstable. </p>
<p>Fortunately, there is an idiom to regain full expressiveness. Instead of declaring `<code>next = curr + 2</code>`, I might declare `<code>next = curr + 2 with cooldown of 2ms</code>`. The cooldown would prevent the operation from applying an infinite number of times, and essentially specifies its own concept of discrete time.</p>
<p>The `cooldown` concept leaves a lot to be desired. What if the write declaration changes and the state is still in cooldown? It seems we might easily miss important writes. But there are other concepts similar to cooldown that achieve the same purpose. I&#8217;ve explored a <a href="http://awelonblue.wordpress.com/2011/12/02/animated-reactive-term-rewriting/">time debt</a> approach and <a href="http://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/">timeouts</a>. </p>
<p><i>Continuous State</i></p>
<p>Continuous-varying state can potentially have a different value at every instant in time. This can be useful for physics simulations; for example, we could precisely model the path of a bullet. But there are a number of new challenges here. </p>
<p>I have only idly explored this space, as it is a mere curio to my current visions. </p>
<p>But I have determined that there aren&#8217;t many <i>simplistic</i> continuous models that actually seem useful. For example, I had considered representing state in terms of an integral of forces, but every practical use-case I&#8217;ve developed calls instead for a system of differential equations (to account for friction, air resistance, etc.). </p>
<p>One model I have found reasonably useful is a continuous follow-the-leader or dangling-carrot behavior, suitable for simple continuous animations (e.g. for a user interface, or robotic motion). I&#8217;ve been wondering if such a model might be generalized in terms of Bezier control points. </p>
<h3>Concurrent Writers in Continuous Time</h3>
<p>Concurrent writers again introduce the challenge of combining writes, resolving write conflicts, and ensuring stability. </p>
<p>For discrete-varying state, combining writes makes it even more difficult to validate whether a fixpoint function will converge. Also, while the time-debt idiom seems to work fairly generically to support multiple writers, it took me a while to discover that pattern.</p>
<p>For continuous-varying state, we can expect continuous-varying declarations to control it (essential, for composition). The problem of combining write declarations and making useful resolutions means we&#8217;ll start to encounter challenges of detecting zero-crossings &#8211; i.e. find the time that signal A becomes less than signal B. Unless our continuous signals are of an analytic nature, detection of zero crossings will generally be imprecise and expensive &#8211; i.e. implemented by sampling near suspected collision points. </p>
<h3>RDP and Declarative State</h3>
<p>RDP falls into that last quadrant. The time model is continuous. Since I <a href="http://awelonblue.wordpress.com/2011/09/28/nothing-new-in-rdp/">cannot create state in RDP</a>, I assume that other writers can also `discover` it, and I also lack freedom to provide an ad-hoc combining function. I must instead `discover` state with an appropriate combiner function already built-in.</p>
<p>The inability for normal developers to introduce ad-hoc combiner functions means I must invent a couple `standard` state models for RDP &#8211; that RDP languages can be assumed to support in the same sense that imperative languages are assumed to support mutable references. </p>
<p>I&#8217;ve written about a few of my efforts and ideas &#8211; <a href="http://awelonblue.wordpress.com/2011/10/04/reactive-state-transition/">reactive state transition</a>, <a href="http://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/">animated reactive state transition</a>, and <a href="http://awelonblue.wordpress.com/2011/12/02/animated-reactive-term-rewriting/">animated reactive term rewriting</a>, among <a href="http://awelonblue.wordpress.com/2011/09/04/stability-and-rdp/">others</a>.</p>
<p>One decent declarative state model that is so simple it is almost beneath mention is simply mutating a set. This is a common state model for temporal logic approaches (such as Berkeley&#8217;s Dedalus and BLOOM), and in practice it is used very much like a tuple space or an SQL table. It works as follows:</p>
<ul>
<li>State is a set of values, initially empty</li>
<li>A declaration can add a value</li>
<li>A declaration can delete a value</li>
<li>In case of conflict, delete wins</li>
<li>Update is modeled as add + delete</li>
<li>Idle behavior is to maintain the current set.</li>
</ul>
<p>Since add and delete operations are idempotent, and commutative with add and delete on other values, there are very few conflicts. The ONLY conflict is adding and deleting the same value. State of an application can be divided across many such spaces.</p>
<p>Unfortunately, this state model isn&#8217;t very effective for a broad class of problems &#8211; in particular, incremental updates of values, such as a editing a textbox. And there are no obvious and simple tweaks to fix that problem without causing other problems.</p>
<p>More practical for a broad spectrum of applications is the <a href="http://awelonblue.wordpress.com/2011/12/02/animated-reactive-term-rewriting/">animated reactive term rewrite</a> state model. It is a most promising `de-facto` option for RDP at the moment &#8211; unless I figure out how to make RST blazing fast and achieve my vision of model <a href="http://awelonblue.wordpress.com/2011/10/05/large-scale-reactive-collections/">reactive databases with reactive indexes</a> and such. </p>
<h3>Conclusions</h3>
<p>This article is not about the utility of declarative state. I speak only about what it means in practice, and how it compares to imperative state. I would like readers to take two things away from this article:</p>
<ol>
<li>how declarative state can be achieved, and the relevant constraints (inflexibility) compared to imperative state models</li>
<li>that resolving concurrent write conflicts is rather arbitrary regardless of the imperative vs. declarative distinction, it just expresses in different ways (e.g. last update wins vs. arbitrary resolution rule)</li>
</ol>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/672/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/672/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/672/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/672/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/672/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/672/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/672/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/672/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=672&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2012/02/16/declarative-state/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Defining `Declarative`</title>
		<link>https://awelonblue.wordpress.com/2012/01/12/defining-declarative/</link>
		<comments>https://awelonblue.wordpress.com/2012/01/12/defining-declarative/#comments</comments>
		<pubDate>Fri, 13 Jan 2012 00:15:13 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Glossary]]></category>
		<category><![CDATA[Language Design]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=617</guid>
		<description><![CDATA[I&#8217;ve seen many definitions for `declarative programming`. The term `declarative` is often contested because it has connotations and market buzz surrounding it &#8211; i.e. there is some advantage to saying your product is `declarative` even if that means stretching the &#8230; <a href="https://awelonblue.wordpress.com/2012/01/12/defining-declarative/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=617&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve seen many definitions for `declarative programming`. The term `declarative` is often contested because it has connotations and market buzz surrounding it &#8211; i.e. there is some advantage to saying your product is `declarative` even if that means stretching the term. I freely admit that I might be guilty of this, too. </p>
<p>My understanding of `declarative` is that it describes a synergistic intersection of several useful properties. Consequently, I can place languages on a lattice for just how declarative they happen to be. This article explains how I reach the definition I favor.</p>
<p>I start with the informal notion of `declaration`:</p>
<blockquote><p><b>declaration</b>: an explicit (written or oral) statement or indication of fact, opinion, or belief.</p></blockquote>
<p>I believe a declarative programming language should enable expressing a program in terms of declarations &#8211; not just one big declaration, but a bunch of smaller statements each indicating a fact, opinion, or belief about the program&#8217;s behavior. For programming, of course, I&#8217;m primarily interested in written declaration. </p>
<p>How am I to recognize that an expression is a declaration? Well, I compare to some ideal properties of declarations. </p>
<ol>
<li>Explicitly stating the same fact, opinion, or belief twice in a given context doesn&#8217;t affect its meaning or truth.</li>
<li>Source, location, and origin of a fact, opinion, or belief doesn&#8217;t affect its meaning or truth. Though, it is sometimes useful to track origin as part of the fact (e.g. `David believes that declarative is &#8230;`).</li>
<li>Facts, opinions, and beliefs have a `continuous` nature &#8211; they hold over time. We can express statements about past events (e.g. `the ball went through the hoop`) but even such statements are true `over time`.</li>
<li>Facts, opinions, and beliefs will name, describe, and relate objects in an implicit environment or system (e.g. `the ball`, `the hoop`). Thus, the meaning of a declaration is actually a function of its environment.</li>
</ol>
<p>Formalizing these concepts gives me the properties I now associate with `declarative` expression:</p>
<ul>
<li><b>idempotent:</b> declarative expressions can be duplicated, and duplicate expressions can be eliminated, without affecting behavior of the program.</li>
<li><b>commutative:</b> declarative expressions can be reordered or reorganized without changing their meaning.</li>
<li><b>concurrent:</b> declarative expressions naturally hold at overlapping times. Declarative systems are implicitly concurrent in the sense of separate expressions holding simultaneously.</li>
<li><b>reactive:</b> declarative expressions hold over time and have meaning relative to their implicit environment. If the environment changes over time, so will the active meaning of the declarative expression. [upd. 1/13]</li>
</ul>
<p>Some people say that declarative is about eliminating `control flow`, but I understand that as a natural consequence of commutativity and concurrency &#8211; and to only be skin deep: control flow isn&#8217;t implicit in the syntax. In my experience, declarative programming is excellent for modeling ad-hoc control flows and work flows in terms of observations and declared rules of action. I point to Berkeley&#8217;s <a href="http://www.eecs.berkeley.edu/Pubs/TechRpts/2009/EECS-2009-173.html">Dedalus</a> paper as offering several good examples.</p>
<p>Some people argue that declarative is about `referential transparency` or `purity`, but I reject this. Declarations don&#8217;t have a `value` so much as they have a meaning relative to their implicit environment. However, idempotence and commutativity together do allow most of the same abstraction and refactoring advantages achieved by referentially transparent code. </p>
<p>Some people claim that declarative is about `what not how`, but there isn&#8217;t any fundamental reason we cannot declare hows instead of whats. To be honest, I&#8217;ve never understood the `what not how` argument &#8211; what vs. how is a difference in perspective, whether you&#8217;re looking up or down the ladder of abstraction. A clever man might try `why not how`. But, again, this seems orthogonal to the notion of declaration &#8211; the decision to declare motivation, intention, or mechanism is just stages of abstraction.</p>
<p>There is simplicity and elegance in having <i>`declarative all the way down`</i> or <i>`everything is declarative`</i>, including IO. The input to such a declarative program is a set of declarations &#8211; essentially, another declarative program. And so is the output. That implies a declarative representation of implicit environment and computed demands, of observation and influence. Such a design would be useful for abstraction, staging, typing, metaprogramming, embedding and extending languages. Declarations of what, why, and how are mixed in a single program, together with declarations to combine and compile them. </p>
<p>Of course, the benefits of `everything is a` designs are hardly unique to declarative. Similar benefits have been argued for functional, OOP, procedural. </p>
<p>While I don&#8217;t list `everything is a` as a criterion for declarative, it would be a fair point in a comparison between languages if arguing which is `more declarative`. Though, I&#8217;m not sure the argument itself would have a point. While `more declarative` is better if all else is equal, all else is probably not equal. </p>
<p>There are many programming models that I count as highly declarative under my definition: constraint, logic, temporal constraint, temporal logic, generative grammars, relational, various forms of dataflow, synchronous reactive, event calculus, functional reactive, and reactive demand. These models vary considerably in other characteristics &#8211; composition, security, resource management, completeness, staging, etc.. But they are all very declarative. </p>
<p>On the other hand, there are many systems that are <a href="http://en.wikipedia.org/wiki/Ostensive_definition">ostensively</a> `declarative` &#8211; such as HTML or pure functional programming &#8211; that I consider to be relatively weak examples of declarative programming (e.g. due to having poor idempotence or commutativity of expressions). Sure, HTML is more declarative than PostScript. And pure functional is somewhat more declarative than procedural (and certainly more cleanly staged). But they aren&#8217;t very high on the declarative lattice. </p>
<p>I posit that functional programming is `declarative` primarily to the extent one is functionally constructing a declarative program.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/617/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/617/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/617/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/617/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/617/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/617/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/617/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/617/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/617/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/617/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/617/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/617/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/617/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/617/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=617&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2012/01/12/defining-declarative/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Social Aspects of PL Design</title>
		<link>https://awelonblue.wordpress.com/2012/01/11/social-aspects-of-pl-design/</link>
		<comments>https://awelonblue.wordpress.com/2012/01/11/social-aspects-of-pl-design/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 21:36:58 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Language Design]]></category>
		<category><![CDATA[Modularity]]></category>
		<category><![CDATA[Open Systems Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=600</guid>
		<description><![CDATA[Software development is ultimately a social experience. And I&#8217;m not just talking about teams of coders. Even sharing or using code via library, or services via API, is a social experience involving communication and relationships between humans. Consequently, there exists &#8230; <a href="https://awelonblue.wordpress.com/2012/01/11/social-aspects-of-pl-design/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=600&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Software development is ultimately a social experience. And I&#8217;m not just talking about teams of coders. Even sharing or using code via library, or services via API, is a social experience involving communication and relationships between humans.</p>
<p>Consequently, there exists a vast array of social concerns surrounding the development experience: discovery, configuration and adaptation, maintenance and upgrade, safety and security, packaging and distribution, trust, reputation, blame, spam, licensing, market integration. If some of these aren&#8217;t obviously language-design concerns today, it is only because we have humans doing most of the footwork. Today, we human developers must purchase, upgrade, package, configure, track licenses, point fingers, and slog through spam. Greater automation and finer granularity will inevitably require a more formal and explicit representation of social policy.</p>
<p>Social concerns should be addressed in programming language designs. My reasoning is thus: Most code and services I use come from strangers. As years pass, I become a stranger even to my own code. An effective social model for programming should lower the barriers and improve confidence in using code and services developed by strangers. I <a href="http://lambda-the-ultimate.org/node/3229#comment-47439">posit</a> that addressing social concerns does more for usability and productivity than addressing `cognitive concerns` (of the individual developer) because social elements will pay for itself manyfold due to network effects. (That said, I do not believe there are many conflicts between social and cognitive design considerations.)</p>
<p>A language designer should consider such cases as how the module system, type system, and <a href="http://lambda-the-ultimate.org/node/3991#comment-60412">namespace</a> model influence the developer&#8217;s social experience. Is it easy and efficient to integrate code that uses a set with code that uses an array? Can developers effectively compose services that use <a href="http://awelonblue.wordpress.com/2011/06/15/data-model-independence/">heterogeneous data models</a>? Is it easy to take code written for GTK and reconfigure or adapt it to use QT? Is it easy to track old configurations for regression testing? How much effort is required to disentangle a useful function or subprogram for use in other projects? Is there any mechanism for cross-project refactoring? Will developers easily experience `<a href="http://en.wikipedia.org/wiki/Dependency_hell">dependency hell</a>`? </p>
<p>Security lowers a social barrier, mitigating need for `trust` or vetting code in advance. An expressive basis for security (such as <a href="http://en.wikipedia.org/wiki/Object_capability_model">object capability model</a>) can also express and enforce interesting social policies within the language and thereby address many social concerns (e.g. <a href="http://lambda-the-ultimate.org/node/2253">Horton</a> protocol).</p>
<p>It might help to have a vision for the social development environment. I have an idea in my head of a <a href="http://c2.com/cgi/wiki?WikiIde">Wiki IDE</a> concept as the basis for code sharing and discovery (and also a live projects on the cloud), with a <a href="http://en.wikipedia.org/wiki/Distributed_Version_Control_System">DVCS</a>-like mechanism to move code between wikis. </p>
<p>Unfortunately, there seems to be a lack of control-tested and empirically validated social models for addressing PL design in particular. I&#8217;ve not read of any `social dimensions of notation` to mirror Thomas Green&#8217;s `<a href="http://en.wikipedia.org/wiki/Cognitive_dimensions_of_notations">cognitive dimensions of notation</a>`. </p>
<p>My own social design efforts are consequently `principled` in nature. Principled design is by no means scientific. It is an even mix of art, reasoning, intuition, and hypothesis, seasoned with a dash of idealism. But it works well in principle <img src='https://s-ssl.wordpress.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . Here are some resources from which I draw guiding principles:</p>
<ul>
<li>Ka Ping Yee&#8217;s <a href="http://people.ischool.berkeley.edu/~ping/sid/">Secure Interaction Design</a></li>
<li>Research on <a href="http://en.wikipedia.org/wiki/Ambient_intelligence">ambient intelligence</a> and <a href="http://en.wikipedia.org/wiki/Ubiquitous_computing">ubiquitous computing</a>.</li>
<li>Research from the <a href="http://en.wikipedia.org/wiki/Computer-supported_cooperative_work">CSCW</a> community</a>
<li>The <a href="http://c2.com/cgi/wiki?WikiDesignPrinciples">wiki design principles</a>.</li>
</ul>
<p>I don&#8217;t expect anyone to share my preferences for principles. But I would like to see more arguments considering the social aspects of PL design. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/600/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/600/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/600/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/600/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/600/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/600/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/600/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/600/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/600/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/600/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/600/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/600/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/600/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/600/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=600&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2012/01/11/social-aspects-of-pl-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Isomorphism is not Enough</title>
		<link>https://awelonblue.wordpress.com/2012/01/03/isomorphism-is-not-enough/</link>
		<comments>https://awelonblue.wordpress.com/2012/01/03/isomorphism-is-not-enough/#comments</comments>
		<pubDate>Wed, 04 Jan 2012 05:26:20 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Language Design]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=607</guid>
		<description><![CDATA[Too often, I see arguments of the general form: &#8220;I can transform feature X into Y, and the reverse, while maintaining relevant properties. I have an isomorphism. Therefore, I don&#8217;t see the difference between X and Y.&#8221; For the arguments &#8230; <a href="https://awelonblue.wordpress.com/2012/01/03/isomorphism-is-not-enough/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=607&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Too often, I see arguments of the general form: &#8220;I can transform feature X into Y, and the reverse, while maintaining relevant properties. I have an isomorphism.  Therefore, I don&#8217;t see the difference between X and Y.&#8221; For the arguments I&#8217;m likely to participate in, X and Y tend to be languages, features, abstractions, protocols, frameworks, or design patterns.</p>
<p>The problem with this line of argument: it assumes transformation is trivial in context, i.e. from the perspective of a language&#8217;s user.</p>
<p>For expressive equivalence, we need continuity and locality in addition to isomorphism. Assuming Px is a program from language X, and Py is a program from Y resulting from the translating Px:</p>
<ul>
<li><b>continuity:</b> every small change in a Px results in a small change in Py. Continuity can be expressed in terms of an asymptotic epsilon bound (as the change in Px approaches zero size, the change in Py also approaches zero).</li>
<li><b>locality:</b> a bounded change in Px results in a change with a corresponding boundary in Py. Essentially, the transform respects modularity and encapsulation.</li>
</ul>
<p>The mathematical terms to learn are <a href="http://en.wikipedia.org/wiki/Homeomorphism">homeomorphism</a> and <a href="http://en.wikipedia.org/wiki/Diffeomorphism">diffeomorphism</a>. </p>
<p>Isomorphism is not enough. But it is a good place to start.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/607/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/607/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/607/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=607&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2012/01/03/isomorphism-is-not-enough/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Animated Reactive Term Rewriting</title>
		<link>https://awelonblue.wordpress.com/2011/12/02/animated-reactive-term-rewriting/</link>
		<comments>https://awelonblue.wordpress.com/2011/12/02/animated-reactive-term-rewriting/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 23:16:20 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Language Design]]></category>
		<category><![CDATA[Reactive Demand Programming]]></category>
		<category><![CDATA[State]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=581</guid>
		<description><![CDATA[Rewrite systems are a general approach for modeling discrete computations and logics. A set of rewrite rules are applied to a term (or graph, or string, etc.) repeatedly until no further rewrites are possible. Rewriting is distinct from functional programming &#8230; <a href="https://awelonblue.wordpress.com/2011/12/02/animated-reactive-term-rewriting/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=581&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://en.wikipedia.org/wiki/Rewriting">Rewrite systems</a> are a general approach for modeling discrete computations and logics. A set of rewrite rules are applied to a term (or graph, or string, etc.) repeatedly until no further rewrites are possible. Rewriting is distinct from functional programming in that the `fixpoint` reduction (repeated application) is implicit, whereas functional expression of the same model would require explicit recursion. Modeling functional programming in a term rewrite system would involve expressing `apply f x` as a term to be reduced, which allows developers to control the number of applications. </p>
<p>I am interested in term rewrite systems (TRS) as a potential discrete state model for reactive demand programming (RDP). Term rewriting is a generalization of <a href="http://en.wikipedia.org/wiki/State_transition_system">state transition systems</a>, which I have already explored as useful state models [<a href="http://awelonblue.wordpress.com/2011/10/04/reactive-state-transition/">1</a>][<a href="http://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/">2</a>]. I mean `animated` and `reactive` in the same sense (and for similar reasons) that I desire them for <a href="http://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/">animated, reactive state transition</a>.</p>
<ul>
<li><b>reactive:</b> the set of rewrite rules may change over time based on influence from the external environment. Rewriting is logically applied at every instant, thus changes in rewrite rules apply immediately. State effectively `reacts` to conditions.</li>
<li><b>animated:</b> it is possible to model time-varying state with a fixed set of rewrite rules, making it easy to `control` or animate external systems over time even when external conditions are stable. A simple example would be incrementing a number once a second.</li>
</ul>
<p>Term rewriting is very expressive compared to state transition, i.e. there is a huge difference in what you can express with a finite set of rewrite rules vs. a finite set of transition rules. In context of RDP, where there are at most a finite set of rules at any given instant, this difference in expressiveness corresponds very directly to a difference in computational power and flexibility. However, such power has a cost: rewriting can easily diverge even with a finite number of rules (whereas state transition can only cycle), and it is much more difficult to control computation costs.</p>
<p>Like state transition, term rewriting may be indeterministic. I will assume some (possibly arbitrary or heuristic, based on structure) strict ordering can be applied to the rewrite rules because determinism is a property I desire for RDP.</p>
<p>A basic reactive term rewriting` state model (without animation) would have the following elements:</p>
<ul>
<li>One <b>term register</b> carries state as a complex term.</li>
<li>A capability to influence a term register by imposing a rewrite rules in the demand value: <code>(s Rules) ~&gt; (s ())</code>, for some discrete-varying signal type `s`. At any given instant, a finite number of rewrite rules are influencing the term register.</li>
<li>A capability to read the term register: <code>(s ()) ~&gt; (s Term)</code>.</li>
<li>A discovery mechanism, allowing developers to pretend term registers are eternal (and orthogonally persistent). This is necessary since there is <a href="http://awelonblue.wordpress.com/2011/09/28/nothing-new-in-rdp/">nothing new in RDP</a>. Also, ability to reset the register.</li>
</ul>
<p>Whenever observed, the term is always stable. Rewrite rules may change from one instant to the next, and the term is instantaneously reduced to a new stable state. Change in the term only occurs as a consequence of change in the rewrite rules.</p>
<p>I was extremely unsatisfied with this basic Reactive Term Rewriting model. First, there are the unpredictable costs and divergence concerns. Second, it seems too difficult to model useful behaviors, such as an integer that increments periodically &#8211; i.e. you cannot ever express a rule of the form `X =&gt; X+1` since that would diverge, but expressing rules of the form (3 =&gt; 4) (and switching to a new rule when conditions change) does not leverage the full extent of term rewriting.</p>
<p>Animated reactive state transition added a couple extra registers to expire and change state, allowing state to change over time even when the influence rules are constant. Naturally, I considered animating reactive state transition as part of that. A simple approach would be to use the same expiration technique: a rewrite rule may have two stages, allowing a further rewrite after some time has passed if no other rule applied in between. But that still has the problems with divergence, unpredictable costs, etc.</p>
<p>More recently, I&#8217;ve found a model that seems more promising for my goals &#8211; based on modeling costs directly. In this model:</p>
<ul>
<li>Each term register is accompanied by an `time debt` register, whose range is &gt;= 0.0.</li>
<li>Each rewrite rule is labeled with two positive, real-valued attributes: maximum time debt, and time cost.</li>
<li>When a rule is applied, the time cost is added to the time debt register.</li>
<li>A rule may not be applied unless the time debt <i>starts</i> less than or equal to maximum specified for that rule.</li>
<li>Rules are always applied favoring those of the highest `maximum time debt`. This ensures that rule selection is independent of the initial time debt, and thus makes the model much easier to predict. (One might call this the `path of least resistance` rule.)</li>
<li>Time debt reduces toward 0.0 at a constant, continuous rate of 1.0 per second.</li>
</ul>
<p>Effectively, developers model how long each rewrite rule takes (logically). Since debt is allowed to build, it is possible to model bursty or cascading computations. Animated behavior is easy. Consider a term rewrite model with just one rule and an enumerable term. While the rule is {rule:X =&gt; X+1, time-cost:1.0, time-debt-max:0.0}, the term would simply increment once per second. Even though the rewrite rule is active at every instant, the time debt is most of the time too high for the rule to apply. Effectively, <i>divergence becomes animation</i>.</p>
<p>There is no absolute cap for time debt, but at any given instant the maximum debt the model can reach is a simple function of the rewrite rules. Since developers can easily cap the amount of computation that occurs in any given period, this animated reactive term rewriting model is suitable for real-time applications. </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/581/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/581/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/581/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/581/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/581/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/581/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/581/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/581/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/581/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/581/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/581/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/581/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/581/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/581/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=581&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2011/12/02/animated-reactive-term-rewriting/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Disjoin: Decision at a Distance</title>
		<link>https://awelonblue.wordpress.com/2011/11/14/disjoin-decision-at-a-distance/</link>
		<comments>https://awelonblue.wordpress.com/2011/11/14/disjoin-decision-at-a-distance/#comments</comments>
		<pubDate>Tue, 15 Nov 2011 03:38:17 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Language Design]]></category>
		<category><![CDATA[Reactive Demand Programming]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=566</guid>
		<description><![CDATA[The disjoin and conjoin behaviors in RDP are the two primitives that connect sums and products: disjoin :: (x :&#38;: (y :&#124;: z)) ~&#62; ((x :&#38;: y) :&#124;: (x :&#38;: z)) conjoin :: ((x :&#38;: y) :&#124;: (x :&#38;: z)) &#8230; <a href="https://awelonblue.wordpress.com/2011/11/14/disjoin-decision-at-a-distance/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=566&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>The disjoin and conjoin behaviors in RDP are the two primitives that connect sums and products:<br />
<code>
<pre>disjoin :: (x :&amp;: (y :&#124;: z)) ~&gt; ((x :&amp;: y) :&#124;: (x :&amp;: z))
conjoin :: ((x :&amp;: y) :&#124;: (x :&amp;: z)) ~&gt; (x :&amp;: (y :&#124;: z))</pre>
<p></code></p>
<p>The disjoin behavior means that we can take a pipeline `x` and split it into two parallel paths based on state of another pipeline (y or z). Conjoin is dual to disjoin, and allows a partial merge of a pipeline in order to execute the same behavior on both paths.</p>
<p><i>A little background:</i> the :&amp;: connective indicates a `product` &#8211; i.e. that two behaviors or pipelines are active in parallel (equal durations) and may be zipped together into tuples. The :&#124;: connective indicates a `sum` &#8211; i.e. only one pipeline is active at any given instant (partitioned durations) based on some earlier decision, and the behaviors might later be merged into one contiguous signal. Use of :&amp;: and :&#124;: represent <i>asynchronous</i> values in that they come from separate pipelines and may have different latencies. `Asynchronous` doesn&#8217;t mean `distributed`, but readily allows for it. The zip and merge operators will synchronize and combine these asynchronous values into a single pipeline. Products and sums are duals, with zip opposite split and merge opposite dup:</p>
<p><code>
<pre>zip :: (Signal s) =&gt; (s x :&amp;: s y) ~&gt; s (x,y)
split :: (SigSplit s) =&gt; s (Either x y) ~&gt; (s x :&#124;: s y)
merge :: (x :&#124;: x) ~&gt; x
dup :: x ~&gt; (x :&amp;: x)</pre>
<p></code></p>
<p>To express equivalent of if/then/else expression is a three step process involving split (lifting boolean into control flow), disjoin (makes environment observable within choice), and merge (which `closes` the if/then/else branches).<br />
<code>
<pre>type EBool = Either () ()
ifThenElse :: (SigSplit s) =&gt; (env ~&gt; rhs) -&gt; (env ~&gt; rhs)
           -&gt; (env :&amp;: (s EBool)) ~&gt; rhs)
ifThenElse onTrue onFalse =
  second split &gt;&gt;&gt; -- lift boolean into local control flow
  disjoin &gt;&gt;&gt;  -- distribute decision to split environment
  (bfst +++ bfst) &gt;&gt;&gt; -- eliminate vestigial boolean
  (onTrue +++ onFalse) &gt;&gt;&gt; -- operations on environment
  merge -- combine results of true and false paths
</pre>
<p></code></p>
<p>Depending on `rhs`, the above could be a statement or expression.</p>
<p>I think this model of ifThenElse is interesting, in that it exposes some inefficiencies and compositional weaknesses of if/then/else. Every decision involves synchronization at three places: on opening the decision (split), on accessing the environment (disjoin), and on closing the decision (merge). For rich expression and composition, developers should favor naked (onTrue +++ onFalse), working with abstract decisions while delaying commitment to their source. The idea is to avoid local decisions and avoid shared environments, push these things closer to the edges of the application.</p>
<p>These conclusions aren&#8217;t unique to RDP. Even down at the CPU level, one might recognize branch prediction concerns as a workaround for the synchronization overheads inherent to if/then/else. There are proposed alternatives even for imperative and functional programming &#8211; cf. <a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.88.1843&amp;rep=rep1&amp;type=pdf">Multi-return Function Call</a> by Olin Shivers and David Fisher [<a href="http://lambda-the-ultimate.org/node/375">LtU node</a>].</p>
<h3>Implementation</h3>
<p>In practical terms, `disjoin` on (x :&amp;: (y :&#124;: z)) can be implemented by a multi-step process:</p>
<ol>
<li>Duplicate the `x` behavior for the LHS and RHS of the :&#124;: connective.</li>
<li>Mask the `x` behavior on the LHS with the activity of `y`, and mask the `x` behavior on the RHS with the activity of `z`.</li>
<li>To generate the `control` signals for y and z, I need something like a `drop` behavior (drop :: forall x . x ~&gt; u ()).</li>
</ol>
<p>Steps 2 and 3 together imply that there is a global `unit` signal type &#8211; `u ()` &#8211; for each RDP behavior, such that every signal can be masked by u (), and every signal can reduce to u (). A global unit type implies a global time model, but still allows for a variety of signal types (i.e. continuous time-varying vs. discrete time-varying signals). Unfortunately, representing existence of this unit type in Haskell is somewhat painful (at least if I want to keep generality, it means enforcing a typeclass on every signal that becomes part of the behavior), and I&#8217;m still working on a `comfortable` way to do so, including tweaks to the signals model I described in an <a href="http://awelonblue.wordpress.com/2011/07/19/signals-in-rdp/">earlier article</a>.</p>
<h3>Static Sums and Dynamic Behaviors in Reactive Models</h3>
<p>I have studied many reactive programming models, in many variations. First-class support for conditional expressions at the reactive layer is a very rare feature. It isn&#8217;t really a <i>necessary</i> feature for anything: dynamic behaviors (generate behavior based on observed conditions or history) and use of decisions as part of the value layer (Either a b) can adequately cover any cases where one might use a static set of choices in the reactive model. </p>
<p>While explaining RDP in the past, I have a few times been presented with a question: why bother with sums when you have dynamic behavior?</p>
<p>First, sums help complete the model, makes it less dependent upon the underlying `value` layer. Indeed, I could lift the notion of `boolean` values into my model (RBool s = s () :&#124;: s ()), and conceptually (though not pragmatically) could model 32-bit integers as products of 32 RBool choices. I don&#8217;t really need any other values than asynchronous ones, so long as I provide some behaviors for `+` and `*` and the like. Sums are, as noted above, the <i>dual</i> to products.</p>
<p>I could wax on about how sums and dynamic behaviors serve nearly orthogonal roles, and about the virtues of duality (sum is yin to product yang), and present analogies to using `case` statements when you could use Church booleans in Haskell.</p>
<p>But here&#8217;s the real reason: performance and stability.</p>
<ul>
<li>Static sum behaviors provide <a href="http://awelonblue.wordpress.com/2011/09/04/stability-and-rdp/">stability</a>, allowing a single behavior to serve under many common conditions, and thus survive longer in context without need to swap out. Stable behaviors avoid set-up and tear-down costs, and support many optimizations (memoization, caching, partial evaluation or tracing JIT) more effectively than volatile behaviors.</li>
<li>Dynamic behavior provides specialization, allowing an application to make only relevant choices based on the observable context and accessible resources. Basically, dynamic behaviors implies dynamic compilation and linking. Developers can pay for a closer approximation to what they use.</li>
<li>Dead-code elimination does not easily cross an `eval` expression since it is difficult to anticipate how much of the environment an evaluated expression will observe or influence. But if `sum` types are inputs or outputs from a dynamic behavior, one can at least avoid synchronization and possibly eliminate dynamic code based on dead sinks (i.e. an output that is dropped by the static context).</li>
</ul>
<p>I envision developers relying on these combined properties, i.e. building towers of reactive <a href="http://lambda-the-ultimate.org/node/2438">staged interpreters</a> and leveraging push-based reactive semantics to more easily identify points of specialization (any interface of slow-changing code with fast-changing code or data).</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/566/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/566/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/566/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=566&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2011/11/14/disjoin-decision-at-a-distance/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Declarative, Reactive Command Line</title>
		<link>https://awelonblue.wordpress.com/2011/10/28/declarative-reactive-command-line/</link>
		<comments>https://awelonblue.wordpress.com/2011/10/28/declarative-reactive-command-line/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 03:28:15 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Open Systems Programming]]></category>
		<category><![CDATA[User Interface]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=532</guid>
		<description><![CDATA[A good command line interface allows its users to pack a lot of useful work into strings the size of twitter messages. There is no room for boiler-plate, no patience even for parentheses. Identifiers must be short. Parameters must have &#8230; <a href="https://awelonblue.wordpress.com/2011/10/28/declarative-reactive-command-line/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=532&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>A good command line interface allows its users to pack a lot of useful work into strings the size of twitter messages. There is no room for boiler-plate, no patience even for parentheses. Identifiers must be short. Parameters must have good defaults. Failure should usually be obvious and safe, allowing users to refine their commands and try again.</p>
<p>A common property of most command-line interfaces today: they are of an imperative, procedural nature. It is difficult to declare the answer before prompted, which ties the model to time. The querying app must often wait for a prompt to be answered &#8211; i.e. interactive rather than reactive. It is difficult to modify an answer to an earlier query (e.g. &#8220;What is your name?&#8221;). Queries on the system are volatile and must be polled to remain up-to-date. System behavior is sensitive to order of expression. A command expressed twice will typically result in two distinct behavior instances.</p>
<p>A declarative, reactive command line would have the following properties:</p>
<ul>
<li>Behavior of system is declarative. That is, users declare how a system behaves with a fair level of idempotence (declaring a behavior twice doesn&#8217;t result in twice the behavior) and commutativity (order of declaration not so critical).</li>
<li>Behavior of system is reactive. Any earlier declaration of behavior may be revoked or modified.</li>
<li>Time is generally implicit, to keep lines short.  It is possible to declare many behaviors as occurring at the same time, i.e. a batch update.</li>
<li>Relationship between user and application may be maintained through command line. Users may anticipate answers to prompts, and declare answers in advance. Users may change declared answer at any time.</li>
<li>Prompts to user are inherently reactive, not interactive, meaning the app does not implicitly wait. If app must wait for valid answer, this must be modeled explicitly in the app &#8211; if(bad_answer) then nothing else doCoolStuff.</li>
<li>Most output to user is also reactive and subject to change over time. I.e. &#8220;Hello, World!&#8221; might later change to &#8220;Hello, Console!&#8221;. This could be expressed quite naturally with graphical output or curses. If streaming, a less natural mechanism might be required &#8211; but it could at least be symmetric to how the user modifies declarations.</li>
</ul>
<p>I envision such a system working a lot like a tuple space: CLI actions add or remove declarations from the space. A simple case might be declaration like `+lights` turning on the house lights, and `-lights` turning them back off. At least one service (the shell) is observing the space and searching for other services to fulfill each request, but I think it might be more interesting to run this in reverse: allow any number of observers to `interpret` the declarations when deciding their behavior, and attach the console to different tuple spaces as needed.</p>
<p>Prompts from the application are given a unique structural identity, e.g. of the form &#8220;com.example.hello.user_name&#8221;, and all prompts on the ID will return the same value, which can be changed over time. Prompts can carry a lot of extra meta-data, including query strings.</p>
<p>Properties such as filters, queries, histories, suggestions and tab-completion, macros, aliases, topics or switching, CSCW, and persistence would help modernize the shell. Structured text data rather than plain strings could improve filters and queries a great deal, and support level of detail. JSON may be a bit too verbose, but something like <a href="http://www.sics.se/~joe/ml9/doc.html">ML9</a> would allow adding just a little structure where necessary and implicitly annotating each declaration with metadata.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/532/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/532/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/532/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=532&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2011/10/28/declarative-reactive-command-line/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Stream vs. Stack</title>
		<link>https://awelonblue.wordpress.com/2011/10/25/stream-vs-stack/</link>
		<comments>https://awelonblue.wordpress.com/2011/10/25/stream-vs-stack/#comments</comments>
		<pubDate>Wed, 26 Oct 2011 02:41:27 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Language Design]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[RDP]]></category>
		<category><![CDATA[Stream]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=524</guid>
		<description><![CDATA[In a recent discussion on PiLuD, a question was asked regarding implications of stream processing relative to the stack-machine concept used by many languages today. I replicate my answer here: Stream processing has low memory locality (touches a lot of &#8230; <a href="https://awelonblue.wordpress.com/2011/10/25/stream-vs-stack/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=524&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In a recent discussion on <a href="http://groups.google.com/group/pilud/browse_thread/thread/b5b56b2d01ea01a2">PiLuD</a>, a question was asked regarding implications of stream processing relative to the stack-machine concept used by many languages today. I replicate my answer here:</p>
<p>Stream processing has low memory locality (touches a lot of code per element), and uses a lot of memory (many buffers). OTOH, it composes well (pipelines, merges), parallelizes well and in an understandable manner (early parts of a pipeline can run in parallel with later parts, and multiple pipelines can easily run parallel side-by-side), and has highly predictable performance characteristics (CPU, latency, memory costs). </p>
<p>Consequently, stream processing is a very effective basis for:</p>
<ul>
<li>high-performance, scalable, parallel or distributed computing</li>
<li>real-time computing</li>
<li>embedded systems where predictable memory is important</li>
</ul>
<p>Stream processing is used heavily for these purposes, both in languages (such as Lucid and Lustre &#8211; synchronous reactive programming) and architectures (OpenGL shader pipelines; flow-based programming; etc.). </p>
<p>A benefit of stream processing is that it&#8217;s `natural` to associate state with locations in a stream. Even in a semantically stateless stream-processing system, developers can easily annotate stateful optimization: caching, memoization, diff processing and compression, filtering equal updates, stability, choking, and so on. By comparison, there is no `natural` way to associate state with a behavior on a stack. Stack activities are naturally ephemeral. Developers can work around the issue by adding a `heap` or static state to their model, albeit at cost of complicating their computation model.</p>
<p>There is considerable variation among stream processing systems regarding what elements of the stream `mean`, and how side-effects and state are supported. Elements in a stream might represent events or a time-varying value. Effects might be triggered on events, continuous, or shifted entirely to system edges. State might be internal, i.e. accumulate history while computing the stream, or externalized to a database or tuple space. There are many design concerns to weigh here, such as events and internal state allow a lot of expressiveness, but using only state can support the language designer in ensuring useful properties like resilience against disruption or consistent view among observers.</p>
<p>Consider: Functional Reactive Programming (FRP) and Reactive Demand Programming (RDP) are both stream processing models. FRP traditionally supports both events and behaviors, allows internal state (causal behaviors, event accumulators) but forces developers to propagate values to the edge of the system to integrate effects. RDP restricts developers to time-varying values, and forbids internal state, but does allow a continuous effects in the middle (including access to external state).</p>
<p>Anyhow, there are many stream processing models, just as there are many stack-based programming models.</p>
<p>IMO, stack-based programming survives on path dependence. It was a moderately effective design for a singular central processing unit and batch-processing applications. But it&#8217;s a rather poor fit for modern computation and service architectures &#8211; whether you&#8217;re considering GPGPUs, OpenCL, or something larger like web-services. And it&#8217;s a terrible fit for interactive or reactive applications, such as GUIs, games, and robot control software. While I mention complications for representing long-lived state, there are many other complications in the stack architecture &#8211; e.g. composing concurrent behaviors. Even if you do pursue stack-basis, you&#8217;d be better off at least modeling it as continuation passing rather than a true stack!</p>
<p>A stack is a fine example of a `simplistic` model that causes complications everywhere else! Stack-based programming hurts its users again, and again, and again. But it&#8217;s hard for humans to recognize such abuse until they&#8217;ve escaped it.</p>
<p>There comes a time when every language designer must make a choice between what is simple and what seems easy&#8230; </p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/524/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/524/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/524/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=524&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2011/10/25/stream-vs-stack/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Freedom and Crutches in Language Design</title>
		<link>https://awelonblue.wordpress.com/2011/10/13/freedom-and-crutches/</link>
		<comments>https://awelonblue.wordpress.com/2011/10/13/freedom-and-crutches/#comments</comments>
		<pubDate>Fri, 14 Oct 2011 02:40:34 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Language Design]]></category>
		<category><![CDATA[Types]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=472</guid>
		<description><![CDATA[Language designers aim to optimize an experience for their prospective users, but the criteria and heuristics by which they &#8216;optimize&#8217; are widely varied and inconsistent (often within a single designer). In this article, I&#8217;ll present two common points of contention &#8230; <a href="https://awelonblue.wordpress.com/2011/10/13/freedom-and-crutches/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=472&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Language designers aim to optimize an experience for their prospective users, but the criteria and heuristics by which they &#8216;optimize&#8217; are widely varied and inconsistent (often within a single designer). In this article, I&#8217;ll present two common points of contention and my opinion on them.</p>
<h3>Freedom</h3>
<p>First is picking a flavor of freedom:</p>
<ul>
<li><b>Anarchy:</b> A language by hackers, for hackers. The individual developer has privilege and power and ambient authority. Typing is a guard rail that developers are free to step across where it suits them. Ad-hoc language extensions and transforms are feasible by use of code-walking macros.</li>
<li><b>Liberating Constraint:</b> The language abridges the authority and power of individuals in order to protect system-scale properties such as safety, security, consistency, resilience, optimizability, and immunity to deadlock.</li>
</ul>
<p>Both of these can improve developer productivity. Anarchy gives the individual more power in an immediate sense &#8211; there is rarely any need to redesign a poorly chosen set of abstractions to fit some forgotten corner case. Liberating constraint aides the developer by ensuring high-quality libraries, and supporting local reasoning about application behavior without reading the details.</p>
<p>This isn&#8217;t a binary choice. Some language designers will choose the constraint route but add an escape hatch, like unsafePerformIO in Haskell. Given a large set of system properties, a language designer might choose to protect some of them and leave others to developers.</p>
<p>I quite firmly favor liberating constraints, without any <i>ambient</i> escape hatches. I believe individual developers will achieve greatest productivity and flexibility by having a massive pool of libraries and resources they can use securely, safely, and effectively &#8211; even in the absence of &#8216;trust&#8217;. Capabilities and RDP demands do offer me a secure mechanism to provide reflection, meta-object protocols, and other ad-hoc effects if necessary &#8211; but entirely within the rules of object capability model and RDP. </p>
<h3>Crutches</h3>
<p>A &#8216;crutch&#8217; in language design is a solution to a problem of <a href="http://en.wikipedia.org/wiki/Accidental_complexity">accidental complexity</a>. Such problems wouldn&#8217;t exist with (a) the foresight to choose a better abstraction and (b) support for desired abstraction need without sacrificing other valuable properties (such as performance).</p>
<p>One example of a language crutch is <i>keyword and default parameters</i>, which simplify development work with large parameter lists. The function <a href="http://www.opengl.org/sdk/docs/man/xhtml/glTexImage2D.xml">glTexImage2D</a> takes nine parameters, for example, and rather than:</p>
<pre><code>glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 256, 256, 0,
  GL_RGBA, GL_UNSIGNED_BYTE, pData)</code></pre>
<p>We could use:</p>
<pre><code>glTexImage2D(target:GL_TEXTURE_2D, internal:GL_RGBA,
  height:256, width:256,
  dataFormat:GL_RGBA, dataType:GL_UNSIGNED_BYTE, theData:pData)</code></pre>
<p>I&#8217;m assuming here that the `level` and `border` parameters default to 0. Obviously this latter form is more verbose, even with the defaults. But many would claim it easier to read, write, and maintain &#8211; properties that some language designers judge more important than terseness. Developers might still have access to ordered parameters, if that is their preference.</p>
<p>Okay, so this was an improvement according to some people. But this is effectively a band-aid for the real problems: </p>
<ol>
<li>glTexImage2D does not use a texture abstraction. A simple refactoring could capture height, width, border, data format, data type, and the buffer itself into a value abstraction of type `Texture`.</li>
<li>Two parameters &#8211; level of detail number, internal format &#8211; are effectively optimization switches that, under ideal circumstances, could be avoided or at least separated.</li>
<li>The &#8216;target&#8217; type is very often GL_TEXTURE_2D. It would be trivial to shift the case of GL_TEXTURE_CUBE_MAP* into a separate function.</li>
</ol>
<p>In practice, it is feasible to reduce the code to simply: <code>glTexImage2D(texData)</code>, by separating the optimization parameters, shifting the cube maps to another function, and capturing the texture information in a dedicated value abstraction. I think most cases of large parameter lists have similar issues, such that better abstractions would avoid the issue. After all, DSLs are typically built of a medium-size vocabulary (e.g. 30-60 elements) of simple, composable functions and primitives.</p>
<p>Naturally, designers lack perfect foresight; languages and abstractions will be imperfect. There will always be some application for crutches or band-aids. The question is whether one should supply such crutches. Regarding crutches:</p>
<ol>
<li>The existence of a crutch reduces incentive to solve the problems. By nature, use of the crutch must be easier than solving the problem. Unattended problems tend to accumulate. Developers become more dependent on the crutch as the number of half-abstracted libraries grow.</li>
<li>More features means more complexity. Due to <a href="http://en.wikipedia.org/wiki/Feature_interaction_problem">feature interaction</a>, this is a combinatorial concern, and thus the extra features will hide flaws and complications in the language design. For example, designers choosing named parameters rarely consider the impact on first-class functions and point-free function composition.</li>
<li>Crutches tend to be &#8216;optional&#8217; in a bad way: the decision has no semantic impact beyond apparent, immediate convenience to the user. They can easily become a source of <a href="http://en.wikipedia.org/wiki/Decision_fatigue">decision fatigue.</a></li>
</ol>
<p>Sadly, language designers and users tend to see use of a feature as proof of its success and utility, without ever recognizing the larger self-fulfilling prophecy or the implications of the fact that a language-crutch is so widely needed.</p>
<p>I do not favor &#8216;crutches&#8217; in language design. In their absence, developers might instead use boiler-plate, frameworks, or design patterns. I&#8217;ve done my best to support proper abstractions in these roles: user-defined syntax (per module), reactive semantics (which covers many frameworks as plain old abstraction, and makes frameworks more composable), easy scatter-gather between data models (to maintain alternative views and abstractions), and securable interaction with ad-hoc foreign services (which can then cover corner cases). </p>
<p>I believe that avoiding crutches (and their obfuscating complexity) will make the weaknesses and pains of a language more obvious, make it easier to identify and resolve most problems by use of libraries, frameworks, and syntactic abstraction, and to catalog the solutions that did not abstract effectively or required too much external support. Developers will have greater awareness of weaknesses in their libraries, and greater incentive to fix them. As the libraries and services improve, so will developer productivity; they won&#8217;t be hindered by dragging a crutch.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/472/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/472/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/472/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=472&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2011/10/13/freedom-and-crutches/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
		<item>
		<title>Animated Reactive State Transition</title>
		<link>https://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/</link>
		<comments>https://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 23:34:10 +0000</pubDate>
		<dc:creator>dmbarbour</dc:creator>
				<category><![CDATA[Language Design]]></category>
		<category><![CDATA[Reactive Demand Programming]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[State]]></category>
		<category><![CDATA[RST]]></category>
		<category><![CDATA[FSM]]></category>

		<guid isPermaLink="false">http://awelonblue.wordpress.com/?p=455</guid>
		<description><![CDATA[In my recent article on Reactive State Transition, I concluded that a transducer variation won&#8217;t work cleanly due to potential for cyclic operations, and the interaction between continuous and discrete time. I must amend this argument. Augmenting RST transitions with &#8230; <a href="https://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/">Continue reading <span class="meta-nav">&#8594;</span></a><img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=455&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In my recent article on <a href="http://awelonblue.wordpress.com/2011/10/04/reactive-state-transition/">Reactive State Transition</a>, I concluded that a <a href="http://en.wikipedia.org/wiki/Finite_state_transducer">transducer</a> variation won&#8217;t work cleanly due to potential for cyclic operations, and the interaction between continuous and discrete time. </p>
<p>I must amend this argument. </p>
<p>Augmenting RST transitions with <b>delay</b> would allow developers to ensure a finite number of discrete transitions between any two instants in continuous time, and would make those transitions directly observable (no need for anticipation). This in turn would allow associating transitions with imperative effects &#8211; i.e. to model a transducer. Assuming an RDP context, one can easily observe the state to decide a continuous RDP behavior for the duration of the state, which can still be useful to model events (e.g. by applying a bunch of rules to other RST machines for a duration of one millisecond).  </p>
<p>A static set of transition rules, with delay, effectively defines a discrete animation which is either cyclic or has a clear endpoint. This internal animation is mostly orthogonal to the external animation of all RST models, which is achieved by reactively adjusting the transition rules. If the design is well chosen, there should be no difficulty </p>
<p>There are some semantic concerns, however, regarding how the two animation models should interact &#8211; e.g. can internal animations be interrupted by changes in external conditions? The rest of this article addresses these concerns.</p>
<h3>First Class Transitions</h3>
<p>An interesting question for this model is whether transitions are first-class states. This is an important design option: </p>
<ul>
<li>If transitions are identified as edges in a graph &#8211; e.g. (3,4) &#8211; then the state transition rules do not identify the edges, and the model is &#8216;committed&#8217; to each transition.</li>
<li>If transitions are labeled and treated as first-class states, then it becomes feasible to model interrupts at any time as an extra edge from a transition state.</li>
</ul>
<p>I am strongly inclined to offer precedence to external reactivity and support for interrupts based on changes in transition rules. This is better for many use cases, and seems to offer many simplicity and elegance advantages: To the observer and persistence systems, state is uniformly structured. To the developer, the notion of `transition` and `primary state` become conceptually interchangeable (e.g. think of transition as the instantaneous step, and the delay as being part of the state). For external RST machines, `reset` can be represented entirely within the model (disable other transition rules, apply *-&gt;0) as opposed to a special feature that bypasses active commitments.</p>
<h3>Delay as Logical Timeout</h3>
<p>Directly assigning delay to transitions seems problematic, unless the decision is <i>committed</i> in the first instant it becomes available &#8211; and I&#8217;ve already decided against that sort of commitment. The problem is that the rules might change a bit, adjusting the delays between two nodes. Conceptually, the history of the rules should not be part of the current state (I want bounded state per RST machine) so there is no way to say: <i>&#8220;hey, I&#8217;ve been in this state for X milliseconds, time to switch based on a rule that has been consistently available for X milliseconds!&#8221;</i> There would also be funky issues with rules changing over time &#8211; e.g. the exact same rule, except for a <i>shorter</i> delay.</p>
<p>A viable alternative is to model the RST machine as providing a simple timer and timeout mechanism. Consider the following:</p>
<ul>
<li>The abstract animated RST machine has three abstract registers (Current,Next,Timeout) and a Clock.</li>
<li>When Clock=Timeout, and Clock is about to increase, Current is assigned the value in Next.</li>
<li>Transition rules consist of four values: (S,T,F,D). Value S describes a starting state (or range thereof). Values T,F identify specific states. D is a delay which must be zero or positive.</li>
<li>A transition is chosen based on matching S against Current. When a transition is selected, this affects both the current and future states for the machine:
<ol>
<li>Current := T</li>
<li>Next := F</li>
<li>Timeout := Clock+D</li>
</ol>
</li>
<li>Rules for the non-animated RST from the prior article are modeled as (S,T,T,0).</li>
<li>Observers of the RST can only see Current state at any given instant in time. Next and Timeout are effectively write-only as part of choosing a transition rule.</li>
</ul>
<p>A very trivial animated RST to perform some action for 1 millisecond after every 999 millseconds:<br />
<code>
<pre>enum { START, ACTIVE, STOP, PERIOD_WAIT }
p = 1.0s
d = 0.001s
m = {(START,ACTIVE,STOP,d), (STOP,PERIOD_WAIT,START,p - d)}</pre>
<p></code></p>
<p>All four states are necessary since delay can only be assigned at a transition. Two states effectively represent labeled `edges` in the graph.</p>
<h3>Resolving Ambiguity</h3>
<p>In the prior article I described how it is important to resolve ambiguity &#8211; even if in an arbitrary manner &#8211; to achieve deterministic, consistent, cheaply fault-tolerant via redundancy, easily verified and validated behavior. Of course, it&#8217;s better to <i>avoid</i> ambiguity than to resolve it, but for a collaborative and reactive system like RDP it can be difficult to prevent ambiguity.</p>
<p>The simple heuristic from the earlier article can still apply with a minor tweak: first filter all the (S,T,F,D) transition  rules that can apply to a given state (by S), then choose the transition rules that lead to the lowest T state. If there is more than one, choose a transition rule that leads to the lowest F state. If there is more than one, choose the transition rule with the lowest delay D. There can be only one.</p>
<p>It is possible to express transitions of the form (S,T,F,0) where T is not equal to F. In this sense, the animated RST might be slightly more expressive than the original RST even for zero-latency transitions.  However, the T-&gt;F state is treated as occurring only at the end of the instant, which means it has the lowest priority relative to other transitions from T. Effectively, after reaching T by an (S,T,F,0) rule, we can add a single-use rule of the form (T,infinity,F,0) for deciding priority.</p>
<h3>Resolving Cycles</h3>
<p>A cycle including T will prevent the T-&gt;F transition from ever firing, since the machine will keep choosing a path other than T-&gt;F. So cycles resolve the same way they do in the prior RST model. Effectively, one can understand a cycle as stabilizing as though an extra rule of the form (L,L,L,0) is introduced, where L is the lowest labeled state in the cycle.</p>
<p>Of course, since T represents a transitory state (an edge), there really shouldn&#8217;t be cycles including T. This is possible only if introducing interrupts in a malformed graph. In practice, it <i>should</i> be a non-issue. In the rare cases it is an issue, at least it will be so deterministically.</p>
<h3>Weaknesses</h3>
<p>As with RST, animated RST has a lot of arbitrariness, which always smells bad to me &#8211; but is not unexpected due the simplistic (overly simple) nature of RST and of state machines in general. </p>
<p>The real problem is fundamental: timeouts. Even when timeouts are deterministic and logical (like in an RDP system), there isn&#8217;t any natural relationship between timeouts and the state of the external systems. No matter what value is locally chosen for a timeout, it&#8217;s arbitrary and wrong! Systems with timeouts do not compose well; inner timeouts easily accumulate to larger values than outer timeouts.</p>
<h3>Conclusions</h3>
<p>Timer and timeout based state machines would support rapid development of simple frame-oriented animations (such as a GIF image) and various simulations. It can be useful for animating periodic activity (e.g. once per second, per minute, per hour, per day). Timeouts apply almost directly to integration and adaptation of event systems, whether to recognize complex events or to decide when to re-deliver a message. </p>
<p>The advantages of RST still apply: State is collaborative without exclusive control. Future RST state at any given instant can easily be <a href="http://awelonblue.wordpress.com/2011/05/28/anticipation-in-rdp/">anticipated</a> to the extent one can anticipate future transition rules, accommodating even the internal animation. State cost is bounded (up to integer type) in any given instant. State is stable within each instant and often across fluctuations in transition rules. The RST machine can easily be modeled as external and eternal, and abstract infinite spaces of integer-labeled RST machines can be provided to model complex reactive memory systems (except now with animated memory!). There is a clean reset state (*-&gt;0). </p>
<p>Animated RST has potential to be a powerful tool in the toolbox. I&#8217;ll certainly try implementing it.</p>
<p>Fortunately for my personal brand of insanity, RDP pushes this arbitrariness to the edges of the system: access to an RST service must be provided as a foreign service, possibly by a language runtime or extension. This allows many arbitrary variations to coexist peacefully. </p>
<p>[Edited heavily 2011 October 19]</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/awelonblue.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/awelonblue.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/awelonblue.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/awelonblue.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/awelonblue.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/awelonblue.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/awelonblue.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/awelonblue.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/awelonblue.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/awelonblue.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/awelonblue.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/awelonblue.wordpress.com/455/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/awelonblue.wordpress.com/455/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/awelonblue.wordpress.com/455/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=awelonblue.wordpress.com&amp;blog=21391232&amp;post=455&amp;subd=awelonblue&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>https://awelonblue.wordpress.com/2011/10/11/animated-reactive-state/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="https://secure.gravatar.com/avatar/5f2716777689db5a800e9cab12812f93?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">dmbarbour</media:title>
		</media:content>
	</item>
	</channel>
</rss>
