<?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/"
	>

<channel>
	<title>while coding &#187; Road To Wheeler</title>
	<atom:link href="http://www.youell.com/matt/writing/?cat=32&#038;feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://www.youell.com/matt/writing</link>
	<description>simplify</description>
	<lastBuildDate>Wed, 31 Oct 2018 04:08:22 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>A Data Structure Runs Through It</title>
		<link>http://www.youell.com/matt/writing/?p=769</link>
		<comments>http://www.youell.com/matt/writing/?p=769#comments</comments>
		<pubDate>Wed, 01 Dec 2010 22:16:58 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=769</guid>
		<description><![CDATA[I&#8217;m surprised to be developing a programming language. I didn&#8217;t know I had a language in me until a few years ago. I always considered new languages kind of a waste. Most of the cool tricks seem to be known. No reason they can&#8217;t be added to existing languages, right?
The past few years of wide-ranging [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m surprised to be developing a programming language. I didn&#8217;t know I had a language in me until a few years ago. I always considered new languages kind of a waste. Most of the cool tricks seem to be known. No reason they can&#8217;t be added to existing languages, right?</p>
<p>The past few years of wide-ranging language interest have cast doubt on that perspective. Still, one theme that I can&#8217;t shake is that you should be able to model new features in an existing language. It might be awkward, but it should still be possible. (Especially if you&#8217;re going to implement the language!)</p>
<p>In that spirit, I&#8217;ve tried to express one of the core ideas in Wheeler with a library for Python called <a href="https://github.com/built/AssociativeTools">AssociativeTools</a>. The star of the show is the Workspace class, which represents a data structure I call an Associative Network.</p>
<p>The word &#8220;network&#8221; is overloaded. Most often it is used to refer to computer networks. Here, I&#8217;m referring to a <a href="http://en.wikipedia.org/wiki/Network_model_(database)">network or web of data</a>. Think of a big pool of data in which nodes can be arranged into graphs of your choosing.</p>
<p>The Workspace lets you relate items (anything that is hashable in Python) to one another. Mostly I&#8217;m using strings and numbers. You relate items to build graphs so that later you can come back and fetch those graphs with partial information. It&#8217;s a lot like querying a database. It&#8217;s more like querying a search engine. Look:</p>
<p><code language="python"><br />
s = Workspace()<br />
s.associate("foo", "bar", "baz")<br />
# Later in the code...<br />
print(s.comprehend("foo"))<br />
</code></p>
<p>Outputs:</p>
<pre>set(['bar', 'baz'])</pre>
<p>Btw, the naming for all of this (AssociativeNetwork, associate, comprehend) is all flexible. Suggestions are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=769</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Introduction To Wheeler, Part 3: Transitions and Mutual Dispatch</title>
		<link>http://www.youell.com/matt/writing/?p=665</link>
		<comments>http://www.youell.com/matt/writing/?p=665#comments</comments>
		<pubDate>Thu, 22 Jul 2010 00:59:10 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[wheeler]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=665</guid>
		<description><![CDATA[Hey, quick, watch this video before you read any further. It&#8217;s under 2 minutes long and it is *fascinating*.

That video is about how cell membranes work. Did you notice how proteins, enzymes, etc. can only pass through the cell membrane if they are the right shape (and flavor)? That&#8217;s how values trigger transitions in Wheeler.
Transitions
If [...]]]></description>
			<content:encoded><![CDATA[<p>Hey, quick, watch this video before you read any further. It&#8217;s under 2 minutes long and it is *fascinating*.</p>
<p><object width="480" height="385"><param name="movie" value="http://www.youtube.com/v/owEgqrq51zY&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/owEgqrq51zY&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="480" height="385"></embed></object></p>
<p>That video is about how cell membranes work. Did you notice how proteins, enzymes, etc. can only pass through the cell membrane if they are the right shape (and flavor)? That&#8217;s how values trigger transitions in Wheeler.</p>
<h3>Transitions</h3>
<p>If categories are the most minimal representation of state, then transitions are the most minimal representation of action. Transitions are how computation happens in Wheeler. After all, organizing data is only half the battle with programming. Once you have the data in the form you want, you have to actually <em>do something</em>.</p>
<p>You can think of transitions as being very much like an event handler. You define a transition to trigger when an interaction between one or more categories happens.</p>
<p>Since Wheeler is still a work in progress, transitions are not yet native. Instead, transitions are created in Python, the language Wheeler is built on.</p>
<p>Remember our Hello example?</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/hello_world_363x174.png" alt=""  style="float: none"/></p>
<p>Here&#8217;s the transition defined for it in Python:</p>
<pre class="syntax-highlight:php">
def printer(category):
	for item in category:
		print item.name[1:-1],
	print
	return []

ROOT.create(&#039;print&#039;).add_handler( STRING, printer )
</pre>
<p>(I&#8217;ve omitted some unimportant details for clarity.)</p>
<p>What you might be able to suss out here is that there is a ROOT category that all categories live within, and I&#8217;ve created a &#8220;print&#8221; category within that. In addition, I&#8217;ve added a transition (with add_handler) which knows to watch for interactions with items in the string category. If the transition finds an interaction that matches, it executes the printer() function, which simply calls Python&#8217;s &#8216;print&#8217; function.</p>
<h3>Mutual Dispatch</h3>
<p>When more than one transition is triggered by an expression, the transitions all execute AND &#8211; at least in concept &#8211; they all execute *at the same time*.</p>
<p>This is very much like the real world. If two objects collide you don&#8217;t say that one or the other of them collided first. The collision is mutual and simultaneous. In that same way, when categories interact, the interaction is mutual and simultaneous.</p>
<p>Here&#8217;s the final snippet of Wheeler for this introduction:</p>
<p><img src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/mutual_dispatch.png" alt=""  style="float: none"/></p>
<p>In case it&#8217;s not clear what is going on here, we have some numbers, which are in the category &#8216;number&#8217;, some text in the category &#8217;string&#8217;, and some other categories (&#8217;print&#8217;, &#8216;+&#8217;) which give it all meaning with transitions. One transition knows to add all of the numbers in the expression when the plus sign is present. Another transition knows to print all of the strings in the expression to stdout when the &#8216;print&#8217; category is present.</p>
<p>When presented with this jumble of categories, Wheeler figures out what to do based on the criteria of the transitions. This effectively creates a typed-dispatch mechanism. I call this simultaneous, polymorphic behavior &#8220;Mutual Dispatch&#8221;.</p>
<p>That sums up Wheeler as currently implemented. </p>
<p>There&#8217;s still a lot of work to be done. I&#8217;ve covered what Wheeler is currently capable of. There are other planned features that I didn&#8217;t cover and hope to implement soon. I will provide more info here as new features are added.</p>
<p>I hope you find it as oddly fascinating as I do! Feedback is not just requested, it is begged for. I also strongly encourage you to <a href="http://github.com/built/wheeler">grab the code</a>, play, and contribute.</p>
<p>(Thanks to Westside Programmers and #pdxfunc for letting me present on Wheeler a few times over the past year. Having the chance to present and receive feedback has firmed up the concepts in my mind and made them easier to distill into this introduction.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=665</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Introduction To Wheeler, Part 2: Values &amp; Types</title>
		<link>http://www.youell.com/matt/writing/?p=663</link>
		<comments>http://www.youell.com/matt/writing/?p=663#comments</comments>
		<pubDate>Wed, 21 Jul 2010 23:57:31 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[wheeler]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=663</guid>
		<description><![CDATA[(Note: It may be helpful to read the posts I did on types several months ago.)
Someone recently asked me if Wheeler had types. My answer was &#8220;No. Uhhh&#8230; and yes.&#8221; What a terrible answer! I&#8217;ll try to do better in this post.
Wheeler has no explicit type system. You will never declare a value to be [...]]]></description>
			<content:encoded><![CDATA[<p>(Note: It may be helpful to read the <a href="http://www.youell.com/matt/writing/?p=601">posts I did on types</a> several months ago.)</p>
<p>Someone recently asked me if Wheeler had types. My answer was &#8220;No. Uhhh&#8230; and yes.&#8221; What a terrible answer! I&#8217;ll try to do better in this post.</p>
<p>Wheeler has no explicit type system. You will never declare a value to be of a certain type. You might, however, associate a value with a particular category through an interaction. In that way you&#8217;re establishing a relationship that will allow typing *behavior*.</p>
<h3>What is a value?</h3>
<p>Values are the imaginary, interstitial things floating between categories. When you establish a relationship between categories in Wheeler, you&#8217;re creating values.</p>
<h3>What is a type?</h3>
<p>I won&#8217;t attempt to answer this in general. I am not a type theorist. From the perspective of Wheeler we might say that a type is determined by a graph&#8217;s &#8220;shape&#8221; and &#8220;flavor&#8221;. Shape is the actual form of the graph we create in memory (tree, ring, object, etc.). Flavor is what specific categories are being connected by that graph.</p>
<h3>What the hell is the difference?</h3>
<p>Context. It&#8217;s all context. A value will trigger typing behavior when something matching that shape and flavor is being watched for. At that point it could be considered a type. The rest of the time, a value.</p>
<h3>Layering values into types</h3>
<p>Have you ever seen an artist paint a landscape? First they&#8217;ll paint the background&#8230; the sky, the horizon, the land. Then they start to layer on more and more detail. At what point does their work become a painting? Existential arguments aside, you might say that the work is a painting when it meets the criteria of the artist. Criteria will vary from artist to artist. Everyone has their own objectives, aesthetics, etc. In other words, everyone brings their own point of view or <em>context</em> to a situation. This idea is so fundamental in Wheeler that it is a core value of the language:</p>
<p><strong>Context Drives Behavior</strong></p>
<p>To help understand this, let&#8217;s look at a Venn diagram. (Venn diagrams are quite handy for discussing concepts in Wheeler.)</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars.png" alt="" /></p>
<p>Here you see we&#8217;ve got just a category, Cars. You could think of that as a type. Let&#8217;s pile on some more specifics:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda.png" alt="" /></p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda_element.png" alt="" /></p>
<p>Now we&#8217;ve got all cars that are Honda Elements. That&#8217;s more specific, but it&#8217;s still more like a type than anything.</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda_element_vin.png" alt="" /></p>
<p>Ah, but now that we have a VIN, the unique Vehicle Identification Number. That&#8217;s so unique as to specify a particular vehicle. That seems more like a concrete value now. Yay.</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/value_cars_honda_element_vin_actual.png" alt="" /></p>
<p><a href="http://www.youell.com/matt/writing/?p=665">Next time</a> we&#8217;ll look at <em>Transitions</em> which allow computation in Wheeler. Then we&#8217;ll exercise our type and value scheme.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=663</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Introduction To Wheeler, Part 1: Categories &amp; Interactions</title>
		<link>http://www.youell.com/matt/writing/?p=659</link>
		<comments>http://www.youell.com/matt/writing/?p=659#comments</comments>
		<pubDate>Thu, 08 Jul 2010 16:07:39 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[programming languages]]></category>
		<category><![CDATA[wheeler]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=659</guid>
		<description><![CDATA[I started my &#8220;Road to Wheeler&#8221; series last year to introduce some of the ideas behind Wheeler, a new programming language I&#8217;ve been developing. Instead of continuing that discussion I&#8217;m going to explain through demonstration. This is the first in a series of posts that will introduce the basic ideas behind Wheeler.
(You can play along [...]]]></description>
			<content:encoded><![CDATA[<p>I started my &#8220;Road to Wheeler&#8221; series last year to introduce some of the ideas behind Wheeler, a new programming language I&#8217;ve been developing. Instead of continuing that discussion I&#8217;m going to explain through demonstration. This is the first in a series of posts that will introduce the basic ideas behind Wheeler.</p>
<p>(You can play along at home by grabbing <a href="http://github.com/built/wheeler">the latest code</a> and running the examples. You&#8217;ll need Python 2.5 and patience.)</p>
<p>First, let&#8217;s fire up &#8220;bigwheel&#8221;, the Wheeler interpreter:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/bigwheel_349x150.png" alt="" /></p>
<p>Here is &#8220;Hello, world&#8221; in Wheeler:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/hello_world_363x174.png" alt="" /></p>
<p>Wheeler is flexible though, so you could also say:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/hello_world2_355x150.png" alt="" /></p>
<p>More on that later.</p>
<h3>Categories</h3>
<p>Wheeler is different from many languages you may be familiar with. All languages have abstractions. Some common examples are functions, lists, collections, stacks, pointers, and objects. In Wheeler, <strong>state</strong> is the fundamental abstraction.</p>
<p>State is represented by an abstraction called a Category. Categories are lightweight, atomic things. In Wheeler, <em>everything</em> is a category. Here are some sample categories:</p>
<ul>
<li>Fred</li>
<li>blue</li>
<li>5.3</li>
<li>&#8220;Hello, world!&#8221;</li>
<li>number</li>
<li>3/15/10</li>
<li>send</li>
<li>05:10:59</li>
<li>AM</li>
<li>PM</li>
<li>true</li>
<li>print</li>
</ul>
<p>Categories express boolean state. You&#8217;re either in a category or you&#8217;re not. Here&#8217;s an example:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_red.png" alt="" /></p>
<p>Do you see that? No? Good. What you do not see is &#8216;apple&#8217; being put into the &#8216;red&#8217; category. That is happening behind the scenes through an <em>interaction</em> between apple and red.</p>
<p>Categories aren&#8217;t containers, but from a practical standpoint they act like containers. This allows you to make statements about the world. We can pile some more attributes on &#8220;apple&#8221;:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_red2.png" alt="" /></p>
<h3>Interactions</h3>
<p>Interactions are expressions that combine categories to create new states. Our &#8220;Hello, world!&#8221; was an example of an interaction. Making our apple red was another interaction. Interaction is a mutual, simultaneous event where a connection (graph edge) is created between each item in the expression.</p>
<p>Wheeler has a &#8220;dump&#8221; command that will let you see (in GraphViz) the relationships you&#8217;ve created. Let&#8217;s dump &#8220;apple&#8221; and see the relationships:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_dump.png" alt="" /></p>
<p>And the relationships as diagrammed in GraphViz:</p>
<p><img style="float: none" src="http://www.youell.com/matt/writing/wp-content/uploads/2010/07/apple_graph.png" alt="" /></p>
<p>Here you can see that &#8220;apple&#8221; is related to &#8220;red&#8221;, &#8220;tasty&#8221;, and &#8220;sweet&#8221;. (You might notice that it is also related to &#8220;dump&#8221;, the category it interacted with to generate our diagram, and &#8220;metadata&#8221;, a built-in category.)</p>
<p>You can see that not only is &#8216;apple&#8217; connected to &#8216;red&#8217;, but &#8216;red&#8217; is also connected to &#8216;apple&#8217;. In Wheeler all relationships are bidirectional. This may seem odd if you&#8217;re used to typical hierarchical relationships in programming. Wheeler doesn&#8217;t think about the world that way. Wheeler has a few strongly-held beliefs, and one of these is:</p>
<p><strong>Hierarchy Is Bullshit</strong></p>
<p><a href="http://www.youell.com/matt/writing/?p=663">Next time</a> we&#8217;ll talk about composing categories into types.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=659</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Typical Types of Typing and the Types They Typify, Part 2</title>
		<link>http://www.youell.com/matt/writing/?p=627</link>
		<comments>http://www.youell.com/matt/writing/?p=627#comments</comments>
		<pubDate>Tue, 17 Nov 2009 11:31:59 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=627</guid>
		<description><![CDATA[Note: This is the conclusion of a two-part entry in my ongoing “Road to Wheeler” series.
In my last post I covered some of the popular type schemes used in programming today. I continued a little past where most discussions of type go when I pulled in pattern matching.
Deconstructing Types
Imagine that you are using a language [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is the conclusion of a two-part entry in my ongoing “Road to Wheeler” series.</p></blockquote>
<p>In <a href="/matt/writing/?p=601">my last post</a> I covered some of the popular type schemes used in programming today. I continued a little past where most discussions of type go when I pulled in pattern matching.</p>
<h4>Deconstructing Types</h4>
<p>Imagine that you are using a language with no data types and you want to implement some of the typing behavior that I showed in my last post. One way you might do it is with a <a href="http://en.wikipedia.org/wiki/Record_%28computer_science%29">record</a> used to associate type information with a value.</p>
<p>A C-style int might look something like this:</p>
<pre class="syntax-highlight:c">
x = (int, 5)
</pre>
<p>That&#8217;s pretty simple. We&#8217;re storing our value along with it&#8217;s type. Using that same scheme we can also represent a typical object instance:</p>
<pre class="syntax-highlight:c">
vendor = (Vendor, FirstName, LastName)
</pre>
<p>&#8220;Vendor&#8221; here is the classname, but it could also be an interface name. Or the record could contain a list of interfaces supported. Or, a list of methods implemented.</p>
<p>The pattern matching example from last time is already in record format. We&#8217;ll just change the Erlang braces to parentheses for continuity with the other examples:</p>
<pre class="syntax-highlight:c">
(customer, FirstName, LastName)
</pre>
<p>Let&#8217;s list all of these records together to compare them:</p>
<pre class="syntax-highlight:c">
(int, 5)
(Vendor, FirstName, LastName)
(customer, FirstName, LastName)
</pre>
<p>See the similarity? The types are from different methodologies, but they boil down to equivalent concepts.</p>
<h4>Our Own Imaginary Type Implementation</h4>
<p>I could easily define a function in my imaginary typeless language to properly handle any of these records:</p>
<pre class="syntax-highlight:python">
def display(record):

	type = record[0] # Key off first item in the record.

	if type == int:
		print_int(record)

	elif type == Vendor:
		print_vendor(record)

	elif type == customer:
		print_customer(record)
</pre>
<p>Is pattern matching a typing scheme? Do typing schemes devolve to pattern matching? </p>
<p>One thing I left out of my pattern matching example from last time: Patterns can match concrete values, such as specific numbers. In this example I&#8217;m expecting to find out just how overdue a customer&#8217;s account is:</p>
<pre class="syntax-highlight:c">
bill_with_msg({customer, 0}) -&gt; send_bill(&quot;Here&#039;s your new bill.&quot;);
bill_with_msg({customer, DaysOverdue}) -&gt; send_bill(&quot;Your bill is ~p days overdue.&quot;, DaysOverdue).
</pre>
<p>The first pattern matches on the atom &#8220;customer&#8221; and the specific value of 0 for the number of days overdue.</p>
<p>If we rewrote this in our typeless language with records it might look something like this:</p>
<pre class="syntax-highlight:python">
def bill_with_msg(record):

	type = record[0]
	days_overdue = record[1]

	if days_overdue == 0:
		send_bill(&quot;Here&#039;s your new bill&quot;)
	else:
		send_bill(&quot;You&#039;re bill is $days_overdue days overdue.&quot;)
</pre>
<h4>Guards Point The Way</h4>
<p>Have you seen guards? They&#8217;re pretty handy. Here&#8217;s an example of guards in Erlang:</p>
<pre class="syntax-highlight:c">
bill_with_msg({customer, 0}) -&gt; send_bill(&quot;New bill.&quot;);
bill_with_msg({customer, DaysOverdue}) when DaysOverdue &lt;= 30 -&gt; send_bill(&quot;Your bill is overdue.&quot;);
bill_with_msg({customer, DaysOverdue}) when DaysOverdue &gt; 30 -&gt; send_bill(&quot;YOUR BILL IS SERIOUSLY OVERDUE. PLEASE PAY NOW.&quot;).
</pre>
<p>Those &#8220;when&#8221; clauses are guards. And they&#8217;re pretty nice. In a fairly concise and clear way we&#8217;ve expressed our desire to do several things with relatively little code. In the process we&#8217;ve managed to unlock a new dimension to typing. If you accept that typing is essentially pattern matching you can see that the guards are actually adding extra dimension to our types by letting us do very specific pattern matching.</p>
<p>The trouble with guards is that they are bound to a function. What if you want to capture a certain type of customer (one who has spent more than $10k this year) so you can target them directly? You might find yourself with functions like this:</p>
<pre class="syntax-highlight:c">
bill_customer(customer, spent) when spent &gt; 10000 -&gt; preferred_billing().

find_shipping_options(customer, spent) when spent &gt; 10000 -&gt; preferred_shipping().

lookup_special_offers(customer, spent) when spent &gt; 10000 -&gt; offer_preferred_promos().
</pre>
<p>That&#8217;s a lot of repetition; a code smell. If you&#8217;re an OO type of person you might break that kind of customer out into it&#8217;s own class, generated by a factory. Or perhaps you might decorate your customer objects with particular account classes. And of course there might be many other strategies.</p>
<p>This might also be a good place for a macro if you&#8217;re a Lisper.</p>
<p>Another way might be to declare a type with the guard built-in. Here&#8217;s one way this might work with some made-up syntax:</p>
<pre class="syntax-highlight:c">
typedef Customer = Customer when spent &lt; 10000
typedef GoldCustomer = Customer when spent &gt;= 10000 and spend &lt; 10000
typedef PlatinumCustomer = Customer when spent &gt;= 100000
</pre>
<p>Here we&#8217;re creating some concise types on top of an existing type. Instead of subtyping or aggregating classes, we&#8217;re taking a class or data structure (Customer) and describing some situations where we&#8217;d like it to be treated specially. Now we can have polymorphic behavior on anything &#8211; types, values, or ranges of values.</p>
<p>This scheme will stretch a little farther:</p>
<pre class="syntax-highlight:c">

typedef Spam = String when contains &quot;viagra&quot;

def proc_mail(Spam msg):
	mark_and_toss()

def proc_mail(String msg):
	deliver(msg)
</pre>
<p>Of course you can only do this with lazy type evaluation, so there&#8217;s some runtime cost. I&#8217;m ok with that. Laziness has its virtues.</p>
<p>What I&#8217;ve presented so far is interesting but still rather flat. We can go farther. What if we can look at the shape of things too? After all, an interface represents a sort of shape. What if you just want to support objects that have a &#8220;Text&#8221; property? What if you only want to deal with Customers who have blue items in their RecentPurchases collection? Or more abstractly, what if we only want to deal with objects that expose a hashtable containing other hashtables?</p>
<p>Sound weird? It shouldn&#8217;t. It happens all the time, it just depends on the environment you work and code in. See also: jQuery, LINQ, RSpec, Hamcrest, etc., etc..</p>
<h4>This Way To The Egress</h4>
<p>I haven&#8217;t seen a type system that does exactly what I describe. Maybe you have. If so I hope you&#8217;ll tell me about it. Haskell&#8217;s type system is pretty nice (and I&#8217;m still learning), but seems to stop short of the dynamic behavior I&#8217;m looking for. Wheeler, the language I&#8217;m working on, aims (at least in part) for something very much like this.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=627</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Typical Types of Typing and the Types They Typify, Part 1</title>
		<link>http://www.youell.com/matt/writing/?p=601</link>
		<comments>http://www.youell.com/matt/writing/?p=601#comments</comments>
		<pubDate>Mon, 02 Nov 2009 09:21:32 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=601</guid>
		<description><![CDATA[Note: This is the first of a two-part entry in my  ongoing &#8220;Road to Wheeler&#8221; series.
In the C language, where I was first introduced to the concept of &#8220;type&#8221;, types are metadata associated with some bytes. Here&#8217;s some C code:

int x = 5;

int z = x + 3;

Here x, z, 5, and 3 are [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Note: This is the first of a two-part entry in my  ongoing &#8220;<a href="http://www.youell.com/matt/writing/?p=583">Road to Wheeler</a>&#8221; series.</p></blockquote>
<p>In the C language, where I was first introduced to the concept of &#8220;type&#8221;, types are metadata associated with some bytes. Here&#8217;s some C code:</p>
<pre class="syntax-highlight:c">
int x = 5;

int z = x + 3;
</pre>
<p>Here x, z, 5, and 3 are all understood to be &#8216;int&#8217;s. What&#8217;s an int? The computer doesn&#8217;t really care. It just knows that an int is going to be a certain number of bytes in memory.</p>
<h4>If She&#8217;s Lucky, I&#8217;ll Show Her My OO Face</h4>
<p>In a common OO language like C++ or Java, we start to think of types in more abstract terms. We&#8217;re no longer thinking solely in terms of memory footprint. Now we&#8217;re thinking in terms of interface. Also, the concept of &#8220;type&#8221; becomes very closely bound with the notion of polymorphism: We expect that a function with two different implementations will &#8220;automagically&#8221; catch the proper value that gets thrown at it:</p>
<pre class="syntax-highlight:java">
// Imagine a few classes, which I won&#039;t bother to fill out:
class Person;
class Customer : Person;
class Vendor : Person;

public void Display(Customer thingy)
{
	// Do something customer-specific here.
}

public void Display(Vendor thingy)
{
	// Do something vendor-specific here.
}
</pre>
<p>That&#8217;s about as far as a lot of programmers in the Java, C# and C++ worlds seem to go in terms of thinking about types. That&#8217;s too bad, because there&#8217;s more going on.</p>
<h4>Quack Quack</h4>
<p><a href="http://en.wikipedia.org/wiki/Duck_typing">Duck typing</a> is the big thing outside of most of the static typing world. Essentially duck typing depends purely on behavior &#8211; if an implicit interface is available, things work. By &#8220;implicit interface&#8221;, I mean if the functions and properties on a class which are expected actually exist. &#8220;If it walks like a duck and quacks like a duck, it must be a duck.&#8221;</p>
<p>Duck typing doesn&#8217;t require a lot of formality, but it&#8217;s still a type strategy. You&#8217;ll find duck typing in languages like Python, Ruby, and Perl. </p>
<p>Btw, not to be outdone, C# 4.0 offers &#8220;<a href="http://msdn.microsoft.com/en-us/library/dd264736%28VS.100%29.aspx">dynamic types</a>&#8221; &#8211; essentially some syntax and internal support to allow duck typing in C# code. It ain&#8217;t pretty, but it is equivalent. (Accordingly, look for it in Java in 5 years and C++ in about 14. /snark)</p>
<p>Hey! Here&#8217;s some code to ponder:</p>
<pre class="syntax-highlight:ruby">
# More hand-waving classes. You get the idea.
class Person
	def show

class Robot
	def show

class Customer &lt; Person
class Vendor &lt; Robot

def display(whatever)
	#do something with a Customer or Vendor. Or Robot or Person. Or whatever has a show method.
	whatever.show
end
</pre>
<p>This works because both classes, though unrelated, have the same method which is expected (show). So duck typing is still interface typing, but without any guarantee. &#8220;Jump and the net will appear&#8221; it one way to look at it. (Most of the time it does!)</p>
<h4>Pattern Matching and Awesomesauce</h4>
<p>Here&#8217;s where I&#8217;m going to take a detour from the norm and talk about pattern matching. Pattern matching is a nifty feature in a number of different languages which lets you capture data and use it polymophically. Most often this is used to isolate a specific piece of data or to differentiate partial functions. It is in that last sense that I&#8217;m most interested in pattern matching as a typing scheme. Here&#8217;s an example in Erlang:</p>
<pre class="syntax-highlight:c">
display({customer, FirstName, LastName}) -&gt;
	show_customer(FirstName, LastName);
display({vendor, FirstName, LastName}) -&gt;
	show_vendor(FirstName, LastName).
</pre>
<p>Just as in the OO example, here we have two overloaded functions and one of them will be selected based on the first argument. What is different here is that we&#8217;re not switching on types, we&#8217;re switching on values. The &#8220;customer&#8221; atom is a value that is being matched. If I had passed in some other atom, like &#8220;vendor&#8221;, that wouldn&#8217;t have matched &#8220;customer&#8221; in the first function signature, so the computer would look at the next function to see if that matches. Luckily in this case I&#8217;ve defined my second function to match &#8220;vendor&#8221;, so it finds a match. Note that I could also have used an underscore (wildcard) in place of &#8220;vendor&#8221;, and matched on anything that had made it that far. Effectively that would have meant &#8220;not a customer&#8221;.</p>
<p>Like with duck typing, we&#8217;re not dealing with an explicit type, but we still have typing behavior. It&#8217;s a different kind of type.</p>
<p>This has turned into a two-parter. I&#8217;ll recap: I&#8217;ve reviewed some common type schemes and bent the concept of &#8220;type&#8221; a little bit. In <a href="http://www.youell.com/matt/writing/?p=627">the next installment</a> I&#8217;m going to bend the idea of &#8220;type&#8221; <em>just a little more</em>. Be sure to come back and see if I break anything.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=601</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Road to Wheeler</title>
		<link>http://www.youell.com/matt/writing/?p=583</link>
		<comments>http://www.youell.com/matt/writing/?p=583#comments</comments>
		<pubDate>Tue, 27 Oct 2009 17:43:35 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Road To Wheeler]]></category>
		<category><![CDATA[wheeler]]></category>

		<guid isPermaLink="false">http://www.youell.com/matt/writing/?p=583</guid>
		<description><![CDATA[Over the summer I sketched out a new programming language which I&#8217;ve tentatively named Wheeler. I&#8217;m still working on the implementation, though I have a crude prototype which I presented last month to the Westside Programmer&#8217;s group in Beaverton. The limited feedback I&#8217;ve received so far (aside from &#8220;WTF?&#8221;) has included comparisons with Prolog and [...]]]></description>
			<content:encoded><![CDATA[<p>Over the summer I sketched out a new programming language which I&#8217;ve tentatively named Wheeler. I&#8217;m still working on the implementation, though I have a crude prototype which I presented last month to the Westside Programmer&#8217;s group in Beaverton. The limited feedback I&#8217;ve received so far (aside from &#8220;WTF?&#8221;) has included comparisons with Prolog and Haskell. I&#8217;d like to talk more about this new language here, but before I do I want to pave the way with some short posts highlighting some of the thinking and motivation behind the language. This is the first post in that series.</p>
<p>From Vonnegut&#8217;s &#8220;Slaughterhouse Five&#8221;:</p>
<blockquote>
<p>Billy couldn&#8217;t read Tralfamadorian, of course, but he could at least see how the books were laid out &#8211; in brief clumps of symbols separated by stars. Billy commented that the clumps might be telegrams.</p>
<p>&#8220;Exactly,&#8221; said the voice.</p>
<p>&#8220;They <em><strong>are</strong></em> telegrams?&#8221;</p>
<p>&#8220;There are no telegrams on Tralfamadore. But you&#8217;re right: each clump of symbols is a brief, urgent message &#8211; describing a situation, a scene. We Tralfamadorians read them all at once, not one after the other. There isn&#8217;t any particular relationship between all the messages, except that the author has chosen them carefully, so that, when seen all at  once, they produce an image of life that is beautiful and surprising and deep. There is no beginning, no middle, no end, no suspense, no moral, no causes, no effects. What we love in our books are the depths of the many marvelous moments seen all at one time.&#8221;</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://www.youell.com/matt/writing/?feed=rss2&amp;p=583</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
