<?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>nodename</title>
	<atom:link href="http://nodename.com/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://nodename.com/blog</link>
	<description></description>
	<lastBuildDate>Wed, 11 Apr 2012 20:39:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>What I Did On My Summer Vacation</title>
		<link>http://nodename.com/blog/2011/07/29/what-i-did-on-my-summer-vacation/</link>
		<comments>http://nodename.com/blog/2011/07/29/what-i-did-on-my-summer-vacation/#comments</comments>
		<pubDate>Sat, 30 Jul 2011 07:46:06 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Generative]]></category>
		<category><![CDATA[geometry]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=790</guid>
		<description><![CDATA[A little geometry project in which I make things move <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2011/07/29/what-i-did-on-my-summer-vacation/">What I Did On My Summer Vacation</a></span>]]></description>
			<content:encoded><![CDATA[<p><center><br />
<a href="/wpEmbeds/HilbertApp/bin-release/HilbertParticleFadeApp2D.html" rel="shadowbox;width=1000;height=1000"><img src="/wpEmbeds/HilbertApp/hype.png" alt="" /></a><br />
 </center></p>
<p>I attended the <a href="http://www.andersonranch.org/workshops/courses/details/index.php?page=digital-media&#038;id=2675">Dynamic Abstraction Workshop</a> taught by <a href="http://joshuadavis.com">Joshua Davis</a> at the Anderson Ranch Arts Center in Snowmass, Colorado, along with several flashy flexy friends. Click on the image to see my student project.</p>
<p>I don&#8217;t even want to tell you what Josh has planned for next year&#8217;s workshop until after I get my ticket!</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2011/07/29/what-i-did-on-my-summer-vacation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Generating Generics: Creating Classes at Run Time in Flash</title>
		<link>http://nodename.com/blog/2011/04/26/generating-generics-creating-classes-at-run-time-in-flash/</link>
		<comments>http://nodename.com/blog/2011/04/26/generating-generics-creating-classes-at-run-time-in-flash/#comments</comments>
		<pubDate>Wed, 27 Apr 2011 04:24:16 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=771</guid>
		<description><![CDATA[A simple demonstration of class generation in Actionscript using the as3-commons-bytecode library
 <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2011/04/26/generating-generics-creating-classes-at-run-time-in-flash/">Generating Generics: Creating Classes at Run Time in Flash</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="https://github.com/nodename/ClassCreationTest">Class Creation Test</a></p>
<p>This is a simple demonstration of class generation in Actionscript using the as3-commons-bytecode library.</p>
<p>Here I demonstrate creating parameterized classes (generics). In this example we create a Tuple class given a spec containing the names, types, and visibilities (public, protected, or private) of the class&#8217;s data members.  The class is named appropriately, e.g. Tuple&lt;String, Point, Rectangle&gt;, and it is given a constructor method that requires parameters of the indicated types in the order that they will have in the tuple.  I use the as3-commons-bytecode library to generate the class, and then load the class into the current ApplicationDomain.  Once a couple of specified classes are loaded, I examine them with describeType() and construct an instance of each generated class.</p>
<p>The bytecode for the constructor doesn&#8217;t depend in any way on the types of the parameters; it&#8217;s just a matter of putting them on the stack and initializing the respective properties with them.</p>
<p>One thing that held me up for a while was determining the proper namespace for protected and local properties. It turns out to be the fully qualified classname with a single colon as the final separator; who knew.</p>
<p>I haven&#8217;t provided accessors for the tuple properties, so for non-public members that would be an &#8216;exercise for the reader&#8217;.</p>
<p>I&#8217;m loading the generated classes immediately, but there&#8217;s code to write them out in swf format as well. So an AIR app like this could be included in a build process&#8230;</p>
<p>I was led to play with as3-commons-bytecode by the exciting work that Mike Labriola and James Ward presented at 360Flex in Denver. They demonstrate a bytecode-based framework for intercepting the load process of a Flex application and performing arbitrary changes before allowing Flex to start up.  The possibilities are vast:</p>
<p><a href="http://www.jamesward.com/2011/04/26/introducing-mixing-loom-runtime-actionscript-bytecode-modification/">Introducing Mixing Loom – Runtime ActionScript Bytecode Modification</a></p>
<p>Generating Generics? Somewhere, somebody must already be Making Mocks!</p>
<p><a class="FlattrButton" style="display:none;" rev="flattr;button:compact;" href="http://nodename.com/blog/2011/04/26/generating-generics-creating-classes-at-run-time-in-flash/"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2011/04/26/generating-generics-creating-classes-at-run-time-in-flash/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Playing 52-Card Pickup To Win</title>
		<link>http://nodename.com/blog/2011/04/17/playing-52-card-pickup-to-win/</link>
		<comments>http://nodename.com/blog/2011/04/17/playing-52-card-pickup-to-win/#comments</comments>
		<pubDate>Mon, 18 Apr 2011 00:13:35 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[Software Architecture]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=752</guid>
		<description><![CDATA[<p>So you come on board without having had a look at the code base. First off you find that the developer build process consists of a page of instructions that require you to do about fifteen more steps than &#8220;svn checkout; import Flash Builder project; profit.&#8221; Then, looking at those steps, you see no mention of <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2011/04/17/playing-52-card-pickup-to-win/">Playing 52-Card Pickup To Win</a></span>]]></description>
			<content:encoded><![CDATA[<p>So you come on board without having had a look at the code base. First off you find that the developer build process consists of a page of instructions that require you to do about fifteen more steps than &#8220;svn checkout; import Flash Builder project; profit.&#8221; Then, looking at those steps, you see no mention of &#8220;linking&#8221; &#8220;libraries&#8221; into the application, but rather of adding a couple of source paths that contain about a thousand Actionscript files.</p>
<p>Your mission, should you choose to accept it, is to sort out the dependencies and break this <em>Close Encounters</em> heap into a tree of libraries. Of course this won&#8217;t be easy; when the code base has grown for a year &#8212; or FIVE &#8212; without that kind of discipline, you&#8217;re bound to have to hack through some pretty thick vines sooner or later.  But there are one or two tools you can use to ease the pain a bit and let you explore the tree, even while you&#8217;re just beginning the inevitable refactoring, and without moving a single source file. This way the development team can continue exactly as before while you fiddle around under their skirts.</p>
<p>The first goal is to separate all those &#8220;other&#8221; source files into one or more projects. So let&#8217;s try to make a single library swc out of all those source files.</p>
<p>You&#8217;re going to need enough heap space to build this uber swc, so follow Hasan Otuome&#8217;s <a href="http://technophi.com/2010/08/12/flash-builder-4-java-heap-space-issues/">instructions</a> for that. Don&#8217;t be stingy here: I gave myself 4096M. You&#8217;re not going to accomplish this on a MacBook Air.</p>
<p>You&#8217;re not going to want the IDE trying to build everything every time you save a little code change, so from here out keep &#8220;Project -> Build automatically&#8221; turned off.</p>
<p>Make a Flex Library Project to hold this swc. You do NOT have to make this project reside at the root of the source path. You can put it anywhere you like, out of the way of the other developers. Just ignore the &#8220;Main source folder&#8221; for your library project, and add the (ideally just one) path to the source as an &#8220;Additional source folder.&#8221;</p>
<p>If the IDE stops responding for a while, be patient. If you run out of Java heap space while trying to build the swc, clean all projects and try again. If that doesn&#8217;t work, give yourself even more heap space.</p>
<p>It may be that your entire tree is just too big to build a single swc from. Barring a RAM upgrade or something, you&#8217;re back to square one. You&#8217;ll have to get started right away figuring out where your first Voronoi shatter will take place. You&#8217;ll want to use smarter tools like &#8220;Find References&#8221; to get a feel for the structure of the code. Ask around &#8211; the other devs may have a pretty clear idea of what should depend on what, even if it&#8217;s not yet strictly true. An obvious choice is sectioning off any third-party code that&#8217;s in the tree. But first check to see whether the developers have modified it so that it depends on in-house code.  I have seen this happen.</p>
<p>Once you&#8217;ve got a swc, you can of course link that into your application instead of having all that code as &#8220;Additional source folders.&#8221;</p>
<p>Repeat.</p>
<p>Eventually you&#8217;ll have to edit some source files. If you&#8217;re still on the project :-)</p>
<p>NEW RULES</p>
<p>Describe the source layout of your project in terms of folder structure and library dependencies.<br />
What third-party libraries do you use? Have you modified them? How and why?<br />
Does your app use a framework? What parts of your app are allowed to communicate with the server and why?<br />
Describe the process for prioritizing tasks. What are the criteria for setting deadlines?<br />
If your project involves FLA animations, how are they integrated into the build? Do they contain code?<br />
Describe your commitment to developing reusable software components. Define &#8220;discovery phase.&#8221;<br />
Do you have any unit tests? Automated build?<br />
Who&#8217;s in charge here?</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2011/04/17/playing-52-card-pickup-to-win/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Haskell Liftoff</title>
		<link>http://nodename.com/blog/2010/12/22/haskell-liftoff/</link>
		<comments>http://nodename.com/blog/2010/12/22/haskell-liftoff/#comments</comments>
		<pubDate>Thu, 23 Dec 2010 05:17:03 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[Haskell, baby!]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=695</guid>
		<description><![CDATA[<p>I&#8217;ve been reading about Haskell for a year or so, but it&#8217;s only lately that I&#8217;ve really started to do any coding in the language.  It&#8217;s really good to finally write some code of my own and see what the compiler thinks about it.</p>
<p>I had to get a few things set up on my computer <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2010/12/22/haskell-liftoff/">Haskell Liftoff</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been reading about Haskell for a year or so, but it&#8217;s only lately that I&#8217;ve really started to do any coding in the language.  It&#8217;s really good to finally write some code of my own and see what the compiler thinks about it.</p>
<p>I had to get a few things set up on my computer before I was motivated to jump in; one was the Haskell Platform, another was the Haskell plugin for Eclipse, and the third was the Gtk2Hs packages for hooking Haskell up to OpenGL.  I wanted to do something with Haskell that I could see on the screen, so I started working with <a href="http://www.amazon.com/Haskell-School-Expression-Functional-Programming/dp/0521644089">The Haskell School of Expression: Learning Functional Programming Through Multimedia</a>.  Gtk2Hs offers a graphics library <em>soegtk</em> that specifically supports, and maintains API compatibility with, this book.</p>
<p>Anyway I thought I&#8217;d relate some of what I&#8217;ve been going through.  I hope that even if you know Haskell, there may be something of interest here.</p>
<p>I do have a bit of a leg up because I&#8217;ve become familiar with certain basic things through reading, but there&#8217;s nothing like actually getting down to it. Still, I had to go lie down for a while after reading Exercise 2.4: </p>
<blockquote><p>Define a function convex :: Shape -> Bool that determines  whether or not its argument is a convex shape (although we are mainly interested in the convexity of polygons, you might as well define it for each kind of shape).</p></blockquote>
<p><a href="http://www.youtube.com/watch?v=n0KHt8xrQkk" rel="shadowbox[post-695];player=swf;width=640;height=385;">Right! What&#8217;s a cubit?</a></p>
<p>OK so at least I should show how far the book had brought me along before hitting me with this.  We started with some type definitions:</p>
<pre>
type Radius = Float
type Side = Float
type Vertex = (Float, Float)
</pre>
<p>These are just typedefs. They don&#8217;t enforce anything.  <strong>Radius</strong> and <strong>Side</strong> are both actually <strong>Float</strong>, so if you mix them up, Haskell won&#8217;t care. They&#8217;re just convenient aliases for existing types that help you express your intent, as we&#8217;ll see in the definition of <strong>Shape</strong> below.</p>
<p>That last type, <strong>(Float, Float)</strong>, is a tuple: a pair of Floats.  A tuple has a fixed length, and a fixed type in each position.</p>
<pre>
data Shape = Rectangle Side Side
           | Ellipse Radius Radius
           | RtTriangle Side Side
           | Polygon [Vertex]
</pre>
<p>Unlike <strong>type</strong>, the <strong>data</strong> keyword does define a new type.  This type is named <strong>Shape</strong>, and the things separated by the <strong>|</strong> symbols &#8212; <strong>Rectangle</strong>, <strong>Ellipse</strong>, <strong>RtTriangle</strong>, and <strong>Polygon</strong> &#8212; are constructors.</p>
<p>In Java, C++, and ActionScript, constructors must have the same name as the type they construct.  In these object-oriented languages, types are realized as classes. In ActionScript, in fact, the constructor is so closely identified with the class that a class can have only one constructor. (This is true of haXe as well &#8212; but in haXe the constructor must be named <strong>new</strong>.)  In Haskell, one constructor may have the same name as the type it constructs, but that wouldn&#8217;t be useful here because we&#8217;re not interested in constructing an abstract Shape.  (I don&#8217;t know enough about Haskell to say that we would <em>never</em> want to do that, though.)</p>
<p>The type names following the constructor constitute its signature; thus <strong>Rectangle</strong> takes two parameters of type <strong>Side</strong>, and so on. Haskell doesn&#8217;t use parentheses to indicate function application.  So clean.</p>
<p>That last type, <strong>[Vertex]</strong>, is a list of Vertices.  Unlike a tuple, a list can have only one type of element, but it may have any number of elements, from none (the empty list <strong>[]</strong>) to infinity (for example the list of positive integers <strong>[1..]</strong>).</p>
<p>The next thing I want to mention, though I didn&#8217;t hear it from the SOE book, is this: constructors don&#8217;t have to have any parameters.</p>
<p>So what does that look like? How about this:</p>
<pre>
data Bool = True | False
</pre>
<p>And there you have it. Haskell has no need of a special Enum type or keyword. It&#8217;s just part of the system.</p>
<p>If you&#8217;re a Flash programmer who&#8217;s been looking at <a href="http://haxe.org/ref/enums">Enums in haXe</a> you may have been bedazzled by the fact that the enums have constructors and the constructors can have parameters. Well, we&#8217;ve just seen that little mashup from the FP side of things.</p>
<p>Moving back to geometry, we now define our first function.  The exercise is: &#8220;define <strong>rectangle</strong> in terms of <strong>Polygon</strong>.&#8221;  (Types and constructors start with an upper-case letter; functions start with a lower-case letter. This is not just a convention.) First we&#8217;ll declare the type of the function:</p>
<pre>
rectangle :: Side -> Side -> Shape
</pre>
<p>OK this looks pretty weird from the imperative-language perspective.  What it says is that rectangle takes two arguments of type Side and returns a Shape.  But the -> symbol appears to have two different uses: separating the argument types from each other, and separating the argument types from the return type. (It&#8217;s like that in haXe, too!)  We&#8217;re going to explain that little quirk after a while, but for now let&#8217;s just put up a stickie and push on.</p>
<pre>
rectangle s t = Polygon [(x, y), (-x, y), (-x, -y), (x, -y)]
                where x = s/2
                      y = t/2
</pre>
<p>This is pretty much plain English or plain Mathish anyway, so I&#8217;ll just note that in Haskell it&#8217;s considered cool to use one- and two-letter variable names.</p>
<p>You should now be able to define the functions <strong>square</strong> and <strong>circle</strong>.</p>
<p>How about another function:</p>
<pre>
area :: Shape -> Float
</pre>
<p>There are four different ways a Shape can be constructed, and they all have different formulas for calculating the area, so how do we write this function?  You might think we&#8217;d have to say something like</p>
<pre>
area s = if s is a Rectangle then bla bla bla...
</pre>
<p>But no, what we do in Haskell is provide several equations for the function, with different parameter specs.  When it&#8217;s time to execute the function, Haskell will go through the equations and use the first one that matches the actual arguments.</p>
<pre>
area (Rectangle s1 s2) = s1 * s2
area (RtTriangle s1 s2) = s1 * s2 / 2
area (Ellipse r1 r2) = pi * r1 * r2
</pre>
<p>The pattern matching at work here is just one of the ways that the flow of control is built into the language.  In many ways, the programmer takes care of getting the data structures right, and the compiler handles the branching, the looping, &#8230; the CONCURRENCY&#8230; In this case we&#8217;ve seen Haskell take care of some branching for us.</p>
<p>Now we also want the area function to handle the last kind of Shape, the Polygon.  Polygon is defined by a list, so before we can write that equation we have to back up a bit and take a digression about lists, how they&#8217;re represented, and how we can operate on them. This is going to show us how we can implement loops in a language lacking <strong>for</strong> or <strong>while</strong> &#8212; well, it&#8217;s no secret really, we use recursion.</p>
<p>In the <strong>rectangle</strong> definition above, we constructed an explicit list of four Vertices.  When we pass a list into a function, we&#8217;re going to want to have a way to deconstruct it. So let&#8217;s introduce the <strong>:</strong> operator, pronounced &#8220;cons.&#8221;  If <strong>xs</strong> is a list and <strong>x</strong> is another element, then <strong>x:xs</strong> is a new list whose head (first element) is <strong>x</strong> and whose tail (everything after the first element) is <strong>xs</strong>.</p>
<pre>
head (x:xs) == x
tail (x:xs) == xs
</pre>
<p><strong>x</strong> and <strong>xs</strong> are very common variable names in Haskell. <strong>xs</strong> is pronounced &#8220;exes.&#8221; A list of <strong>xs</strong>.</p>
<p>These next few examples are from <a href="http://book.realworldhaskell.org/">Real World Haskell</a>.</p>
<pre>
-- square every element in the list
squares :: [Float] -> [Float]
squares (x:xs) = x * x : squares xs
squares [] = []
</pre>
<p>This function is complete, because the second pattern matches the empty list, and the first pattern matches any other list of Floats. Notice that <strong>x:xs</strong> matches when the list is just <strong>[x]</strong> &#8212; in this case <strong>xs</strong> is the empty list <strong>[]</strong>.</p>
<pre>
x:[] == [x]
</pre>
<p>Optimization nerd alert: recurring on the tail results in what? Tail recursion! Which gives me the opportunity to mention another thing that Haskell (and other functional language implementations) do for you: they optimize tail recursion to run in constant space.  The recursion doesn&#8217;t grow the stack like it does in your imperative language. So we&#8217;re cool there.</p>
<pre>
upperCase :: String -> String
upperCase (x:xs) = toUpper x : upperCase xs
upperCase [] = []
</pre>
<p>By the way,
<pre>type  String  =  [Char]</pre>
<p>, so <strong>squares</strong> and <strong>upperCase</strong> have exactly the same structure.  What&#8217;s different? The type of the list elements, and the function that&#8217;s applied to each element. Let&#8217;s generalize <strong>squares</strong> by extracting as a parameter the function that it applies:</p>
<pre>
-- f every Float in the list
ff_it :: (Float -> Float) -> [Float] -> [Float]
</pre>
<p><strong>ff_it</strong> is a function that takes two arguments:<br />
1. a function that takes a <strong>Float</strong> and returns a <strong>Float</strong>, and<br />
2. a list of <strong>Float</strong>s;<br />
and returns a list of <strong>Float</strong>s.</p>
<pre>
ff_it f (x:xs) = f x : ff_it f xs
ff_it _ [] = []
</pre>
<p>The underscore in the last pattern is a wildcard; if we fall through to this pattern we don&#8217;t need to match the f, because we won&#8217;t be using it anyway.</p>
<p>SO: if we define a function <strong>square</strong></p>
<pre>
square :: Float -> Float
square x = x * x
</pre>
<p>then instead of using our special <strong>squares</strong> function we can say</p>
<pre>
-- square every Float in the list:
squared_xs =  ff_it square xs
</pre>
<p>and similarly</p>
<pre>
negate :: Float -> Float
negate x = -x

-- negate every Float in the list:
negated_xs = ff_it negate xs
</pre>
<p>Of course it gets tedious to write <strong>ff_it</strong> this and <strong>ff_it</strong> that all the time, so let&#8217;s bring back our <strong>squares</strong> function by defining it this way:</p>
<pre>
squares = ff_it square
</pre>
<p>Where&#8217;s the <strong>xs</strong>, though, right? We defined <strong>ff_it</strong> to take two arguments&#8230;</p>
<p>&#8230;</p>
<p>&#8230;OK so now we have to go back to the arrows in the function signatures and come clean about what they really mean.</p>
<p>Here&#8217;s the thing: every function in Haskell takes just one argument.</p>
<p>The <strong>-></strong> operator is right-associative.  The signature</p>
<pre>
multiply :: Float -> Float -> Float
</pre>
<p>is identical to</p>
<pre>
multiply :: Float -> (Float -> Float)
</pre>
<p>which we already know means &#8220;a function that takes a Float and returns (a function that takes a Float and returns a Float).&#8221;</p>
<pre>
multiply x y = x * y

add x y = x + y
</pre>
<p>As long as we supply at least one argument, any Haskell function will return something.</p>
<pre>
double :: Float -> Float
double = multiply 2

increment :: Float -> Float
increment = add 1
</pre>
<p>This is called <em>partial application</em>.<br />
Can you define a Haskell function that takes no arguments?  I don&#8217;t think so.  Certainly there&#8217;s no function that just &#8220;does something&#8221; without returning anything. There&#8217;s no &#8220;Void&#8221; type for it to not return. (By the way, this is why in AS3 they changed <strong>Void</strong> to <strong>void</strong>: it&#8217;s not a type, it&#8217;s the lack of a type.)</p>
<p>Now let&#8217;s generalize <strong>upperCase</strong> the same way we generalized <strong>squares</strong>:</p>
<pre>
-- f every Char in the list
fc_it :: (Char -> Char) -> [Char] -> [Char]
fc_it f (x:xs) = f x : fc_it f xs
fc_it _ [] = []
</pre>
<p>And we now have two functions that are structurally the same but differ in only one thing: that type that appears as the argument and return types of f and as the element type of the list.</p>
<p>It would be great if we had variables that represent types, right?</p>
<pre>
-- f every a in the list
f_it :: (a -> a) -> [a] -> [a]
f_it f (x:xs) = f x : f_it f xs
f_it _ [] = []
</pre>
<p>Using our now-uncloaked knowledge of the -> operator, this is how we read the type declaration:<br />
<strong>f_it</strong> is a function that takes:<br />
.. a function that takes some type <strong>a</strong> and returns the same type;<br />
and returns:<br />
.. a function that takes a list of that same type <strong>a</strong> and returns a list also of that same type.</p>
<p>It&#8217;s customary to use letters from the beginning of the alphabet for type variables.</p>
<pre>
squares = f_it square
upperCase = f_it toUpper
</pre>
<p>There&#8217;s one more generalization of <strong>f_it</strong> that&#8217;s cool to make that wasn&#8217;t revealed by <strong>squares</strong> and <strong>upperCase</strong>, because they return the same type as their last argument (talking about it in the old pre-enlightenment way). But they could return a different type, say <strong>b</strong>, and we&#8217;d be covered by this more general and equally strongly-typed definition:</p>
<pre>
map :: (a -> b) -> [a] -> [b]
map f (x:xs) = f x : map f xs
map _ [] = []
</pre>
<p>(Of course this includes the case where <strong>a</strong> and <strong>b</strong> are the same.)<br />
Whew, all that just to get to the <strong>map</strong> function that&#8217;s in the standard library and that you probably know about already in some other language!  Too fast?</p>
<p>So clean. Just look at what a hash ActionScript makes of it: <a href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/Vector.html#map%28%29">AS3 function map(callback:Function, thisObject:Object = null):Vector.&lt;t&gt;</a><br />
HaXe does a somewhat better job : <a href="http://blackdog66.wordpress.com/toolbox/haxe-the-functional-parts/">Functional haXe</a></p>
<p>So I hope you noticed that<br />
a. Every function has no side effects either in or out; its action can&#8217;t change or be changed by anything external. Its return value depends solely on its inputs. They&#8217;re called pure functions.<br />
b. no variable ever changes value. They&#8217;re immutable.</p>
<p>Ya think that might be thread-safe? Ah, the concurrency!</p>
<p>Now no useful language can have only pure functions; there would be no way to do any IO!  So Haskell does have impure functions, but it makes it very clear where the membrane lies.  In fact you can tell an impure function from its signature alone: it will always have the word &#8220;IO&#8221; in it!</p>
<p>I see I haven&#8217;t gotten back to the <strong>convex</strong> function, or even to the area of a Polygon, but I&#8217;m afraid our time is up for this week. If you thirst for more of this saga, leave a comment begging for it.</p>
<p>PS If you had any trouble with the <strong>square</strong> and <strong>circle</strong> definitions, here they are:</p>
<pre>
square s = Rectangle s s
circle r = Ellipse r r
</pre>
<p><a class="FlattrButton" style="display:none;" rev="flattr;button:compact;" href="http://nodename.com/blog/2010/12/22/haskell-liftoff/"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2010/12/22/haskell-liftoff/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>The Arrogant Enum</title>
		<link>http://nodename.com/blog/2010/10/13/the-arrogant-enum/</link>
		<comments>http://nodename.com/blog/2010/10/13/the-arrogant-enum/#comments</comments>
		<pubDate>Thu, 14 Oct 2010 02:49:21 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=686</guid>
		<description><![CDATA[<p>This enum thinks it&#8217;s the last word in ActionScript enumerated-type implementations.  In fact it thinks it&#8217;s so hot that it calls itself the Ultimate Enum.  Check it out and see if it doesn&#8217;t do the trick for you.  If it doesn&#8217;t, please let me know and I hope we can improve it further.</p>
<p>Example <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2010/10/13/the-arrogant-enum/">The Arrogant Enum</a></span>]]></description>
			<content:encoded><![CDATA[<p><a href="http://github.com/nodename/Ultimate-Enum">This enum</a> thinks it&#8217;s the last word in ActionScript enumerated-type implementations.  In fact it thinks it&#8217;s so hot that it calls itself the Ultimate Enum.  Check it out and see if it doesn&#8217;t do the trick for you.  If it doesn&#8217;t, please let me know and I hope we can improve it further.</p>
<p>Example enum classes using this implementation are <a href="http://github.com/nodename/Ultimate-Enum/tree/master/src_test/examples">here</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2010/10/13/the-arrogant-enum/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Blobs in Games: Polygon Map Generation, by Amit Patel</title>
		<link>http://nodename.com/blog/2010/10/02/blobs-in-games-polygon-map-generation-by-amit-patel/</link>
		<comments>http://nodename.com/blog/2010/10/02/blobs-in-games-polygon-map-generation-by-amit-patel/#comments</comments>
		<pubDate>Sat, 02 Oct 2010 23:20:07 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ボロノイ]]></category>
		<category><![CDATA[Delaunay]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=670</guid>
		<description><![CDATA[<p>Amit Patel has published a great article on map generation based upon Voronoi polygons.  He generates the Voronoi polygons using my as3delaunay library.  But the polygons are just the beginning of his process&#8230;</p>
<p>Try the demo!  And &#8212; yum &#8212; see the <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2010/10/02/blobs-in-games-polygon-map-generation-by-amit-patel/">Blobs in Games: Polygon Map Generation, by Amit Patel</a></span>]]></description>
			<content:encoded><![CDATA[<p>Amit Patel has published a <a href="http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/">great article on map generation</a> based upon Voronoi polygons.  He generates the Voronoi polygons using my <a href="http://github.com/nodename/as3delaunay">as3delaunay library</a>.  But the polygons are just the beginning of his process&#8230;</p>
<p><a href="http://www-cs-students.stanford.edu/~amitp/game-programming/polygon-map-generation/mapgen2.swf">Try the demo!</a>  And &#8212; yum &#8212; <a href="http://github.com/amitp/mapgen2">see the source code!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2010/10/02/blobs-in-games-polygon-map-generation-by-amit-patel/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Trees Grow</title>
		<link>http://nodename.com/blog/2009/12/14/trees-grow/</link>
		<comments>http://nodename.com/blog/2009/12/14/trees-grow/#comments</comments>
		<pubDate>Mon, 14 Dec 2009 13:54:48 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[geometry]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=194</guid>
		<description><![CDATA[Constrained minimum spanning trees as shape fills, the moving version of my earlier post The Name of the Node. <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/12/14/trees-grow/">Trees Grow</a></span>]]></description>
			<content:encoded><![CDATA[<style type="text/css">
#theMovie {
margin: 0 auto;
width: 640px;
border-width: 1;
border-style : solid ;
border-color : black ;
}
</style>
<p>Constrained minimum spanning trees as shape fills, the moving version of my earlier post <a href="http://nodename.com/blog/2009/05/12/the-name-of-the-node/">The Name of the Node</a>. On each frame one point is added, all the points move, and their spanning trees are drawn. Character: JIE2, &#8220;knot&#8221;.</p>
<div id="theMovie"><object width="640" height="505"><param name="movie" value="http://www.youtube.com/v/BHO6zeW9sQA&#038;hl=en&#038;fs=1&#038;rel=0&#038;ap=%2526fmt%3D18"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/BHO6zeW9sQA&#038;hl=en&#038;fs=1&#038;rel=0&#038;ap=%2526fmt%3D18" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="640" height="505"></embed></object></div>
<p>(Be sure to view the movie in 480p.)</p>
<p>Note that since the segments are filled with trees, which may branch but never loop, the KOU3 (&#8220;mouth&#8221;) in the lower right quadrant is never a closed box. In every frame there is an escape path from the inside to the outside.</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/12/14/trees-grow/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Roll Over, Delaunay: Voronoi Library Goes Open-Source</title>
		<link>http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/</link>
		<comments>http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 04:28:55 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[ボロノイ]]></category>
		<category><![CDATA[Delaunay]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=377</guid>
		<description><![CDATA[I've released the as3delaunay library on github! <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/">Roll Over, Delaunay: Voronoi Library Goes Open-Source</a></span>]]></description>
			<content:encoded><![CDATA[<p>A few people have asked for the code for my <a href="http://nodename.com/blog/2009/05/11/a-voronoi-toy/">Voronoi Toy</a>.  I haven&#8217;t made the entire program public yet, but I have released the underlying <a href="http://nodename.github.com/as3delaunay/">as3delaunay library</a>, which I originally ported from Steven Fortune&#8217;s C implementation of his plane-sweep algorithm.</p>
<p>In addition to the Voronoi diagram and the Delaunay triangulation, the library also provides the convex hull, minimum and maximum <a href="http://nodename.com/blog/2009/05/12/the-name-of-the-node/">spanning trees</a>, and several other related geometric entities.</p>
<p>You can download the source and compile it, or just get the compiled swc from the downloads page.</p>
<p>So far I have had two users, JakeTastic (<a href="http://jaketastic.com/blog/voronoi-shattering-complete/">Voronoi shattering complete!</a>) and Li (<a href="http://www.lidev.com.ar/?p=303">Faster Voronoi Noise</a>); thanks to them both for jumping on, and to Jake also for finding the two bugs :-)</p>
<p>There&#8217;s no documentation yet, but there is a <a href="http://github.com/nodename/as3delaunayTestRunner">test suite</a> which incorporates an example of using the library for nearest-site queries, and there&#8217;s also a <a href="http://groups.google.com/group/as3delaunay">mailing list</a>, where I&#8217;ve archived Fortune&#8217;s paper and his C code, as well as a growing page of interesting <a href="http://groups.google.com/group/as3delaunay/web/resources">links</a> related to Voronoi/Delaunay.</p>
<p>The library is hosted on github, so YOU can conveniently modify, fix, or enhance it!</p>
<p>Roadmap for possible enhancements:<br />
Generalize to support weighted Voronoi diagrams, both additive and multiplicative (This is described in Fortune&#8217;s paper)<br />
Generalize to use an arbitrary polygon as a boundary<br />
&#8230; what else?</p>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/12/03/roll-over-delaunay-voronoi-library-goes-open-source/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Implementing Enumerated Types in ActionScript 3</title>
		<link>http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/</link>
		<comments>http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/#comments</comments>
		<pubDate>Sun, 06 Sep 2009 03:39:33 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[ActionScript]]></category>
		<category><![CDATA[enumerated types]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=363</guid>
		<description><![CDATA[<p>UPDATE  I&#8217;ve improved on this implementation; please see the later post The Arrogant Enum.</p>
<p>This is about implementing an enum in AS3 with value restriction ( i.e. the programmer should be unable to diminish or add to the set of values) and type safety.</p>
<p>We&#8217;ll implement the data type as a Class.  In order to keep <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/">Implementing Enumerated Types in ActionScript 3</a></span>]]></description>
			<content:encoded><![CDATA[<p><strong>UPDATE</strong>  I&#8217;ve improved on this implementation; please see the later post <a href="http://nodename.com/blog/2010/10/13/the-arrogant-enum/">The Arrogant Enum</a>.</p>
<p>This is about implementing an enum in AS3 with value restriction ( i.e. the programmer should be unable to diminish or add to the set of values) and type safety.</p>
<p>We&#8217;ll implement the data type as a Class.  In order to keep the programmer from adding to the set of values, we need to disallow invocation of the constructor.</p>
<p>Back when AS3 came out, there was much talk about the lack of private constructors and what to do about it, especially with regard to implementing the Singleton pattern. My favorite of the solutions is to define a file-level class and require it (the class, not an instance!) as a constructor parameter.</p>
<p>From there we can proceed just as Daniel Savarese describes in <a href="http://www.devx.com/getHelpOn/10MinuteSolution/20442/1763">Implementing Enumerated Types in Java</a>. </p>
<p>I don&#8217;t show how to implement an ordering on the enum values.  See the Savarese article for that, too.</p>
<pre>
package
{
	import flash.errors.IllegalOperationError;

	public final class PailContents
	{
		public static const WATER:PailContents = new PailContents(PrivateConstructorEnforcer, "water");
		public static const CHICKENFEED:PailContents = new PailContents(PrivateConstructorEnforcer, "chicken feed");
		public static const MILK:PailContents = new PailContents(PrivateConstructorEnforcer, "milk");
		public static const OATS:PailContents = new PailContents(PrivateConstructorEnforcer, "oats");

		private var _name:String;

		public function PailContents(lock:Class, name:String)
		{
			super();
			if (lock != PrivateConstructorEnforcer)
			{
				throw new IllegalOperationError("Invalid constructor access");
			}
			_name = name;
		}

		// don't forget to implement toString() to support implicit conversion to String for trace() etc:
		public function toString():String
		{
			return _name;
		}

	}
}

// defined outside the package, and therefore visible only within this source file:
class PrivateConstructorEnforcer {}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/09/05/implementing-enumerated-types-in-actionscript-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Googling myself with Voronoi</title>
		<link>http://nodename.com/blog/2009/08/22/googling-myself-with-voronoi/</link>
		<comments>http://nodename.com/blog/2009/08/22/googling-myself-with-voronoi/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 05:38:39 +0000</pubDate>
		<dc:creator>alan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[3D]]></category>
		<category><![CDATA[ボロノイ]]></category>
		<category><![CDATA[morph]]></category>
		<category><![CDATA[Voronoi]]></category>

		<guid isPermaLink="false">http://nodename.com/blog/?p=264</guid>
		<description><![CDATA[<p>No, this isn&#8217;t about some hot new way of using Voronoi diagrams to google myself; I&#8217;ll leave that challenge to Mario.</p>
<p>I was looking over the search terms that had led people to my blog today, and decided to click on &#8220;Alan Shaw&#8221; Voronoi.  Among all the recent stuff, I came across some papers and articles <span style="color:#777"> . . . &#8594; Read More: <a href="http://nodename.com/blog/2009/08/22/googling-myself-with-voronoi/">Googling myself with Voronoi</a></span>]]></description>
			<content:encoded><![CDATA[<p>No, this isn&#8217;t about some hot new way of using Voronoi diagrams to google myself; I&#8217;ll leave that challenge to <a href="http://quasimondo.com">Mario</a>.</p>
<p>I was looking over the search terms that had led people to my blog today, and decided to click on <a href="http://www.google.com/search?q=%22alan+shaw%22+voronoi">&#8220;Alan Shaw&#8221; Voronoi</a>.  Among all the recent stuff, I came across some papers and articles from my pre-Flash (and pre-C++) days:</p>
<p><a href="http://www.archive.org/details/automaticconstru00shaw">Automatic construction of polyhedral surfaces from voxel representations (1988)</a></p>
<p><a href="http://www.archive.org/details/generalizedmapma00schw">Generalized map makers problem: optimal flattening of polyhedral surfaces</a></p>
<p><a href="http://eslab.bu.edu/publications/articles/1988/schwartz1988applications.pdf">Applications of Computer Graphics and Image Processing to 2D and 3D Modeling of the Functional Architecture of Visual Cortex</a></p>
<p><a href="http://eslab.bu.edu/publications/articles/1989/schwartz1989numerical.pdf">A Numerical Solution to the Generalized Mapmaker&#8217;s Problem: Flattening Nonconvex Polyhedral Surfaces</a></p>
<p>Now to reread them after twenty years and see if they were all bullshit.</p>
<blockquote><p>We achieved reasonable performance on a Sun-2 microprocessor system (which is roughly comparable to a VAX-750).</p></blockquote>
<p>Uh huh.</p>
<p>Here&#8217;a a video by <a href="http://www.youtube.com/user/mike40033">mike40033</a>:</p>
<style type="text/css">
#theMovie {
margin: 0 auto;
width: 425px;
</style>
<div id="theMovie"><object width="425" height="344"><param name="movie" value="http://www.youtube.com/vQpIHlqkrBVM&#038;hl=en&#038;fs=1&#038;rel=0"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/QpIHlqkrBVM&#038;hl=en&#038;fs=1&#038;rel=0" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></div>
]]></content:encoded>
			<wfw:commentRss>http://nodename.com/blog/2009/08/22/googling-myself-with-voronoi/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>

