<?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>Whiley</title>
	<atom:link href="http://whiley.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://whiley.org</link>
	<description>A Programming Language with Extended Static Checking</description>
	<lastBuildDate>Tue, 24 Jan 2012 03:45:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Whiley v0.3.13 Released!</title>
		<link>http://whiley.org/2012/01/24/whiley-v0-3-13-released/</link>
		<comments>http://whiley.org/2012/01/24/whiley-v0-3-13-released/#comments</comments>
		<pubDate>Tue, 24 Jan 2012 03:45:24 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Wyjc]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3325</guid>
		<description><![CDATA[<p>Well, it&#8217;s been almost two months in the making, but here&#8217;s the next release of Whiley.  Quite of lot of changes, although there remain significant issues to resolve &#8212; particularly with the front-end.</p> ChangeLog Fixed outstanding problem with list and set types related to type tests.  More specifically, on the negative branch of a <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2012/01/24/whiley-v0-3-13-released/">Whiley v0.3.13 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s been almost two months in the making, but here&#8217;s the next release of Whiley.  Quite of lot of changes, although there remain significant issues to resolve &#8212; particularly with the front-end.</p>
<h2>ChangeLog</h2>
<ul>
<li>Fixed outstanding problem with list and set types related to type tests.  More specifically, on the negative branch of a type test the correct type was not always being calculated.</li>
<li>Added support for open records.</li>
<li>Added a CONTRIBUTORS file for recording project contributors.  This is based on the <a href="http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob;f=Documentation/SubmittingPatches">developers certificate of origin</a> used by the Linux Kernel.</li>
<li>Changed syntax for processes to be now &#8220;references&#8221;.  This avoids conflicting the name with OS processes.  So, e.g. type <code>process T</code> becomes <code>ref T</code>.</li>
<li>Changed syntax for dereferncing objects to use <code>*</code> and <code>-&gt;</code>, similar to C.</li>
<li>Changed syntax for maps from e.g. <code>{1-&gt;2}</code> to <code>{1=&gt;2}</code>.  This is to avoid conflict with <code>-&gt;</code> for dereferencing.</li>
<li>Changed syntax for processes to syntax for references.  So, e.g. type <code>process {int x}</code> becomes <code>ref {int x}</code>.  The motivation for this choice is simply to avoid confusion with OS processes.</li>
<li>Changed Wyil bytecode to support various &#8220;effective&#8221; types (e.g. sets, lists, dictionaries).  These enable more efficient operation across a union of similarly kinded types.  For example, we can index into a list of type [int]|[bool] without having to coerce into a list of type <code>[int|bool]</code>.</li>
<li>Worked hard to get constraints being expanded properly again.  This is working pretty well now for the most part.</li>
<li>Added support for Maven compilation (thanks Lee).</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.13.tgz" title="Download wdk-src-v0.3.13">wdk-src-v0.3.13</a><br />
      Created on January 24, 2012.  12 Downloads, 2.3 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.13.jar" title="Download wyjc-v0.3.13">wyjc-v0.3.13</a><br />
      Created on January 24, 2012.  12 Downloads, 1.1 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/bench/wybench-v0.1.6.tgz" title="Download wybench-v0.1.6">wybench-v0.1.6</a><br />
      Created on January 24, 2012.  12 Downloads, 5.8 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2012/01/24/whiley-v0-3-13-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connecting the Dots on the Future of Programming Languages</title>
		<link>http://whiley.org/2012/01/18/connecting-the-dots-on-the-future-of-programming-languages/</link>
		<comments>http://whiley.org/2012/01/18/connecting-the-dots-on-the-future-of-programming-languages/#comments</comments>
		<pubDate>Wed, 18 Jan 2012 01:15:24 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Interest]]></category>
		<category><![CDATA[Concurrency]]></category>
		<category><![CDATA[Haskell]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3505</guid>
		<description><![CDATA[<p>Yesterday, I serendipitously came across two things which got me thinking about the future of programming languages:</p> The first was an excellent article entitled &#8220;Welcome to the Hardware Jungle&#8221; by Herb Sutter. This article is about the coming advent our multicore overlords. Whilst this might sound like something you&#8217;ve heard before, it&#8217;s actually well <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2012/01/18/connecting-the-dots-on-the-future-of-programming-languages/">Connecting the Dots on the Future of Programming Languages</a></span>]]></description>
			<content:encoded><![CDATA[<p>Yesterday, I serendipitously came across two things which got me thinking about the future of programming languages:</p>
<ol>
<li>The first was an excellent article entitled <a href="http://herbsutter.com/welcome-to-the-jungle/">&#8220;Welcome to the Hardware Jungle&#8221;</a> by Herb Sutter.  This article is about the coming advent our multicore overlords.  Whilst this might sound like something you&#8217;ve heard before, it&#8217;s actually well worth the read.  His argument is that heterogeneous massively-multicore computing is fast becoming the norm, and there is no turning back.  I found the article quite scary, as I can&#8217;t imagine programming in the extreme environment suggested.  I also have to question whether everyday applications will really benefit from massive multicore.  But, clearly, I can see that quite a few will.</li>
<li>The second was the following (short) youtube video of <a href="http://en.wikipedia.org/wiki/Simon Peyton Jones" target="_top" >Simon Peyton Jones</a> and <a href="http://en.wikipedia.org/wiki/Erik Meijer" target="_top" >Erik Meijer</a> discussing the space of programming languages:
<p><center><iframe width="420" height="315" src="http://www.youtube.com/embed/iSmkqocn0oQ?feature=player_embedded" frameborder="0" allowfullscreen></iframe></center></p>
<p> Simon talks about how both imperative and functional programming languages are trying to reach some kind of &#8220;Nirvana&#8221;, but coming at it from different directions.</li>
</ol>
<p>Now, the question is: <em>how do they connect together?</em> Well, essentially, I think the &#8220;Nirvana&#8221; space the Simon talks about is exactly the space we need to deal with the Hardware Jungle.  In other words, I think it&#8217;s the space most suitable for distributed and parallel computing.</p>
<p><em>What do we know about this “Nirvana” space?</em> In the video, Simon talks about <em>safe</em> and <em>unsafe</em> languages. He says explicitly that safe means having limited or highly controlled <a href="http://en.wikipedia.org/wiki/Side_effect_%28computer_science%29">side-effects</a>. Languages which are unsafe by his categorisation include Java, C#, C, and the majority of languages traditionally thought of as imperative or object oriented. They are unsafe because one cannot reason about the result of any given method in isolation from others. That is, methods may read/write shared state (via the heap) and, to reason about them, we must know: (1) what shared state is actually accessed; (2) what value it has when it is accessed. These three requirements make it very difficult know what’s going on, particularly if something else could modify the state at any point. More importantly, I believe, <em>is that these requirements make it very difficult for the compiler to reason about what’s going on</em>.</p>
<p><em>What does this have to do with the Hardware Jungle?</em>  Well, I believe there are two important points here:</p>
<ol>
<li>To move the right data for a given computation onto the right core, we must know exactly what state that computation will access.</li>
<li>For massively multi-core systems, Humans will not be capable of optimally mapping resources onto cores.  We will increasingly rely on sophisticated algorithms to do this for us.  Typically, such algorithms will be embedded in the compiler and/or runtime system.</li>
</ol>
<p>These two points taken together imply it must be possible to automatically determine what state a given computation will access.  <em>The easiest way of doing this is to aggressively restrict the state that can be accessed by requiring <a href="http://en.wikipedia.org/wiki/Functional_programming#Pure_functions">pure functions</a></em>.  Furthermore, I believe it is not sufficient to rely on the programmer to ensure his/her functions are pure &#8212; the compiler must do this for us.  This is because race-conditions are already notoriously difficult to debug <em>and in the Hardware Jungle things will get seriously crazy</em>.</p>
<p>This leads me to the final and, I think, most important question:</p>
<blockquote><p>
Which mainstream programming languages currently support pure functions and/or other mechanisms for aggressively limiting side-effects?
</p></blockquote>
<p><a href="http://en.wikipedia.org/wiki/Haskell (programming language)" target="_top" >Haskell</a> is clearly one example, <a href="http://en.wikipedia.org/wiki/D (programming language)" target="_top" >D</a> is another.  <em>But, what else?</em>  </p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2012/01/18/connecting-the-dots-on-the-future-of-programming-languages/feed/</wfw:commentRss>
		<slash:comments>19</slash:comments>
		</item>
		<item>
		<title>Three Rules for Programming Language Syntax?</title>
		<link>http://whiley.org/2012/01/11/three-rules-for-programming-language-syntax/</link>
		<comments>http://whiley.org/2012/01/11/three-rules-for-programming-language-syntax/#comments</comments>
		<pubDate>Wed, 11 Jan 2012 00:49:04 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Lisp]]></category>
		<category><![CDATA[SmallTalk]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3455</guid>
		<description><![CDATA[<p>I&#8217;m always pondering the question: what makes good programming language syntax? One thing occuring to me is that many languages often ignore the HCI aspect.  For me, it&#8217;s a given that the purpose of a programming language is to simplify the programmer&#8217;s life, not the other way around.</p> <p>So, I thought of a few <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2012/01/11/three-rules-for-programming-language-syntax/">Three Rules for Programming Language Syntax?</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m always pondering the question: <em>what makes good programming language syntax?</em> One thing occuring to me is that many languages often ignore the <a href="http://en.wikipedia.org/wiki/Human-computer interaction" target="_top" >HCI</a> aspect.  For me, it&#8217;s a given that <em>the purpose of a programming language is to simplify the programmer&#8217;s life, not the other way around</em>.</p>
<p>So, I thought of a few simple rules:</p>
<ol>
<li><strong>Syntax should explain.</strong> The purpose of syntax is to help explain a program to a human.  In particular, structure in the program should be made explicit through syntax.</li>
<li><strong>Syntax should be concise.</strong> The converse to (1) is that syntax should always add to the explanation.  Syntax which does not add value simply obscures the explanation.</li>
<li><strong>Syntax should conform.</strong> The are many things people learn from everyday life, and we should not force them to unlearn these things.  Doing so can confuse the explanation, especially for non-experts.</li>
</ol>
<p>I&#8217;m sure there are plenty of others you can think of.  I pick on these because I see them being broken constantly.  Let&#8217;s illustrate with some of my pet peeves:</p>
<h3>Colons in Type Declarations?</h3>
<p>There are plenty of programming languages which use colons in type declarations (<a href="http://en.wikipedia.org/wiki/ML (programming language)" target="_top" >ML is a classic example</a>).  It goes something like this:</p>
<pre class="brush: whiley;">
fun f (0 : int) : int = ...
</pre>
<p>For me, this breaks rule (2) because those colons do not add value.  The C-family of languages is evidence that we can happily live without them.  That&#8217;s not to say that C-like declaration syntax is the &#8220;one true way&#8221;; only that it demonstrates we don&#8217;t need those colons!</p>
<h3>Function Call Braces: To Be or Not To Be?</h3>
<p>Some programming languages require braces around the arguments to a function call, whilst others (e.g. <a href="http://en.wikipedia.org/wiki/Haskell (programming language)" target="_top" >Haskell</a>) don&#8217;t.  Consider this:</p>
<pre class="brush: whiley;">

(f (g h) 1 2) y 3
</pre>
<p>What can you tell about the invocation structure from this line? <span style="text-decoration: line-through;"> Not much, unless you happen to know from memory exactly what arguments each function takes.</span> This violates rule (3) since functions are normally expressed with braces in mathematics.</p>
<p>Now, how about this:</p>
<pre class="brush: whiley;">

f(g(h),1,2)(y,3)
</pre>
<p>Personally, I prefer this style.  However, it would be fair to say that it violates rule (2) since the comma&#8217;s are not strictly necessary.  I suppose, in fact, we have a contradiction between (2) and (3) in this case, since commas are generally used to deliniate lists in written English.</p>
<h3>Why Don&#8217;t we Teach Polish Notation at School?</h3>
<p><em>(answer: because we don&#8217;t)</em></p>
<p>Some programming languages require mathematical expressions be expressed in <a href="http://en.wikipedia.org/wiki/Polish notation" target="_top" >Polish notation</a> (a.k.a. prefix notation).  For example, in <a href="http://en.wikipedia.org/wiki/Lisp (programming language)" target="_top" >Lisp</a>, we write <code>(+ 1 2)</code> to mean <code>1+2</code>. This violates rule (3), since most people have learned mathematics at school where the usual convention applies.</p>
<p>Similarly in <a href="http://en.wikipedia.org/wiki/Smalltalk" target="_top" >SmallTalk</a>, the expression <code>2+3*4</code> is equivalent to <code>(2+3)*4</code> rather than <code>2+(3*4)</code>, as might be expected.  Again, this violates rule (3) and is particularly insidious because it&#8217;s rather subtle.</p>
<p>The point here is not to say that e.g. one notation is <em>fundamentally better</em> than the other.  Just that, we learn one in school, so we should stick with that.</p>
<h2>Conclusion</h2>
<p>Well, if you made it this far, great!  Hopefully there was some food for thought, and maybe you can suggest some other examples&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2012/01/11/three-rules-for-programming-language-syntax/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>Merchants of Doubt</title>
		<link>http://whiley.org/2011/12/27/merchants-of-doubt/</link>
		<comments>http://whiley.org/2011/12/27/merchants-of-doubt/#comments</comments>
		<pubDate>Tue, 27 Dec 2011 00:29:57 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Book Reviews]]></category>
		<category><![CDATA[Books]]></category>
		<category><![CDATA[Econmomics]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3414</guid>
		<description><![CDATA[<p style="text-align: center;"></p> <p>I&#8217;ve just finished reading this book, which I have to say was really good.  The book is about how a handful of rogue scientists deliberately spread disinformation on a range of key issues, including tobacco, acid rain, the ozone hole and climate change.  Their key strategy was to argue the science <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/12/27/merchants-of-doubt/">Merchants of Doubt</a></span>]]></description>
			<content:encoded><![CDATA[<p style="text-align: center;"><img class="aligncenter" style="border: 0pt none;" title="Merchants of Doubt" src="http://www.desmogblog.com/sites/beta.desmogblog.com/files/blogimages/Merchants%20of%20Doubt.jpg" alt="" width="300" height="300" /></p>
<p>I&#8217;ve just finished reading this book, which I have to say was really good.  The book is about how a handful of rogue scientists deliberately spread disinformation on a range of key issues, including tobacco, acid rain, the ozone hole and climate change.  Their key strategy was to argue the science was inconclusive (even when it really wasn&#8217;t), that the scientists involved had some ulterior motive and, of course, to make such claims without evidence.  I found the stories both disturbing and eye-opening, especially with the underhand tactics being employed.  The key protaganists are <a href="http://en.wikipedia.org/wiki/Fred Singer" target="_top" >Fred Singer</a>, <a href="http://en.wikipedia.org/wiki/Frederick Seitz" target="_top" >Frederick Seitz</a>, <a href="http://en.wikipedia.org/wiki/William Nierenberg" target="_top" >William Nierenberg</a>, and many others.  These people have a lot to answer for.</p>
<p>Perhaps the most interesting question is: <em>why?</em> Why do former scientists (who made good contributions in their field) go on the warpath to undermine science itself?  As a scientist myself, it seems unbelievable.  However, I think the book hits the nail on the head: they are <a href="http://en.wikipedia.org/wiki/Market fundamentalism" target="_top" >free-market fundamentalists</a>.  This view holds that the so-called <a href="http://en.wikipedia.org/wiki/Laissez faire" target="_top" >Laissez faire</a> (i.e. do nothing) approach to regulation is always the right approach.  Alan Greenspan is perhaps the most notable free-market fundamentalist of recent times &#8230; and look where that ended up!</p>
<p>Anyhow, definitely worth a read.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/12/27/merchants-of-doubt/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whiley Talk at Wellington JUG (VIDEO)</title>
		<link>http://whiley.org/2011/12/22/whiley-talk-wellington-ju/</link>
		<comments>http://whiley.org/2011/12/22/whiley-talk-wellington-ju/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 00:03:23 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Tutorial]]></category>
		<category><![CDATA[Video]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3407</guid>
		<description><![CDATA[<p>Last month, the Wellington Java User Group was kind enough to invite me to give a talk on Whiley.  The talk is a general introduction to Whiley, including the syntax, some issues related to implementation and inter-operation with Java.  The talk was video and, finally, after some faffing around I&#8217;ve uploaded it onto YouTube <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/12/22/whiley-talk-wellington-ju/">Whiley Talk at Wellington JUG (VIDEO)</a></span>]]></description>
			<content:encoded><![CDATA[<p>Last month, the Wellington Java User Group was kind enough to invite me to give a talk on Whiley.  The talk is a general introduction to Whiley, including the syntax, some issues related to implementation and inter-operation with Java.  The talk was video and, finally, after some faffing around I&#8217;ve uploaded it onto YouTube here:<br />
<center><iframe width="560" height="315" src="http://www.youtube.com/embed/t-9epw8nhXU" frameborder="0" allowfullscreen></iframe></center><br />
Anyway, enjoy!</p>
<p><strong>UPDATE:</strong> Thanks to Evan for suggesting upload the slides as well &#8212; <a href="http://whiley.org/wp-content/uploads/2011/12/JUG2011-Whiley.pdf">you can get them here</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/12/22/whiley-talk-wellington-ju/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Efficient Value Semantics for Whiley</title>
		<link>http://whiley.org/2011/12/13/efficient-value-semantics-for-whiley/</link>
		<comments>http://whiley.org/2011/12/13/efficient-value-semantics-for-whiley/#comments</comments>
		<pubDate>Tue, 13 Dec 2011 00:34:44 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Value Semantics]]></category>
		<category><![CDATA[Wyjc]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3354</guid>
		<description><![CDATA[<p>The latest release of the Whiley compiler (v0.3.12) includes an optimisation for passing compound structures (e.g. lists, sets and records) by value.  This is really important because all compound structures in Whiley have value semantics, meaning they are always passed by value.  In fact, Whiley does not support references or pointers as found in <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/12/13/efficient-value-semantics-for-whiley/">Efficient Value Semantics for Whiley</a></span>]]></description>
			<content:encoded><![CDATA[<p>The latest release of the Whiley compiler (v0.3.12) includes an optimisation for passing compound structures (e.g. lists, sets and records) by value.  This is really important because all compound structures in Whiley have <em>value semantics</em>, meaning they are always passed by value.  In fact, Whiley does not support references or pointers as found in other languages (e.g. Java, C, etc).  This means Whiley is really more of a <a href="http://en.wikipedia.org/wiki/Functional programming" target="_top" >functional programming language</a> than an <a href="http://en.wikipedia.org/wiki/Imperative programming" target="_top" >imperative language</a>.  As we&#8217;ll see, compared to other functional languages, Whiley is a little unusual as it supports <em>imperative updates</em> to compound structures.</p>
<h2>An Example</h2>
<p><em>So, what does this all mean?</em> Well, let&#8217;s have a look at an examples:</p>
<pre class="brush: whiley;">
[real] normalise([real] data, real max):
    for i in 0..|data|:
        data[i] = data[i] / max
    return data

void ::main(System sys):
    original = [1.2,2.3,4.5]
    normalised = normalise(original,0.5)
    sys.out.println(original)
    sys.out.println(normalised)
</pre>
<p>This function updates a list of real values in-place using a typical (imperative) list assignment of the form <code>data[i] = ...</code>.  In Java, where variables of array type are references to array objects, this would simultaneously update the callers version of this array as well.  In Whiley, however, this is not the case.  The list assignment inside <code>normalise()</code> does not modify the <code>original</code> list in <code>main()</code>.  This is because the list is <em>passed-by-value</em> in the true sense of the word.  You can think of this as meaning that <em>the whole list is copied when the normalise function is called</em> to prevent any interference between caller and callee.</p>
<h2>(In)efficiency?</h2>
<p><em>Ok, but that all that copying must be crazily inefficient! </em>Well, not so.  This is because, whilst the semantics of Whiley dictate pass-by-value for compound structures, the underlying implementation actually passes them by reference.  Furthermore, it clones them lazily with reference counting being employed to reduce the situations where a clone is actually required.  Before explaining how the reference counting works, let&#8217;s look at some actual data first:</p>
<table>
<tbody>
<tr>
<th>Name</th>
<th>Description</th>
<th>LOC</th>
<th># Clones</th>
<th>%</th>
<th>Time</th>
</tr>
<tr>
<td>Jasm</td>
<td>A Java bytecode disassembler.</td>
<td>2333</td>
<td>12878 / 29968</td>
<td>43.0%</td>
<td>2.1s</td>
</tr>
<tr>
<td>Gunzip</td>
<td>An implementation of DEFLATE.</td>
<td>815</td>
<td>873 / 140561</td>
<td>0.62%</td>
<td>1.6s</td>
</tr>
<tr>
<td>Chess</td>
<td>Validates chess games in short algebraic notation.</td>
<td>784</td>
<td>6438 / 416116</td>
<td>1.6%</td>
<td>1.4s</td>
</tr>
<tr>
<td>Calculator</td>
<td>An arithmetic expression evaluator.</td>
<td>225</td>
<td>0 / 81527</td>
<td>0.0%</td>
<td>8.8s</td>
</tr>
</tbody>
</table>
<p><em>What is this data showing us?</em> Well, &#8220;# Clones&#8221; shows the number of clones actually performed versus the number that a naive implementation of value semantics would have performed.   The naive version clones whenever an argument is passed or returned from a function, whenever a list element is assigned, etc.  It represents an upper bound on the number of clones required.  So, for example, looking at the Gunzip benchmark we see that only 873 clones were required out of a maximum of 140561.  This indicates that, in the vast majority of cases, value semantics does not actually result in many extra clones.</p>
<p><em>But the results for Jasm look quite bad?</em> Well, yes.  But, actually, they&#8217;re not too bad if we consider the cause.  Essentially, the Jasm benchmark consists of an inner loop for decoding bytecodes.  Roughly speaking, it looks like this:</p>
<pre class="brush: whiley;">
([Bytecode],int) decode([byte] data, int pos):
    opcode = Byte.toUnsignedInt(data[pos])
    kind,fmt,type = decodeTable[opcode]
    switch fmt:
        case FMT_EMPTY,
            ....
        case FMT_I8:
            idx = Byte.toUnsignedInt(data[pos+1..pos+2])
            return {offset: pos-14, op: opcode},pos+2
        case FMT_I16:
            idx = Byte.toUnsignedInt(data[pos+3..pos+1])
            return {offset: pos-14, op: opcode},pos+3
        case FMT_VARIDX:
            index = Byte.toUnsignedInt(data[pos+1..pos+2])
            return VarIndex(pos-14, opcode, index),pos+2
        ...
</pre>
<p>What we see is that the loop first reads the opcode byte and then, based on this, reads zero or more additional bytes  (e.g. <code>data[pos+1..pos+2]</code>).  This sublist operation is the root cause of almost every  clone reported in the above table for Jasm.  In fact, it&#8217;s not a clone of the entire <code>data</code> list; rather, it just copies those few bytes being read into a new list &#8212; meaning it&#8217;s not really very expensive.</p>
<h2>Implementation</h2>
<p><em>So, how does the reference counting work?</em> One of the key optimisations is knowledge of when a variable is no longer <em>live</em>.  For example:</p>
<pre class="brush: whiley;">
[int] f([int] xs):
   ys = xs // ref count not increased
   ys[0] = 1
   return ys
</pre>
<p>Here, the variable <code>xs</code> is dead after the assignment to <code>ys</code>.  Therefore, we don&#8217;t need to increase the reference count of the object it refers to as, effectively, ownership is transferred from <code>xs</code> to <code>ys</code>.  If the reference count of <code>xs</code> on entry was 1, then it will still be 1 at the assignment <code>ys[0] = 1</code> and, hence, the assignment can be performed in place.  Now, let&#8217;s consider a more detailed example:</p>
<pre class="brush: whiley;">
  [int] f([int] z):
      z[0] = 1 // Object #2 created
      return z

  [int] g():
      x = [1,2,3] // Object #1 created
      y = f(x)
      return x + y
</pre>
<p>On Line 6,  Object #1 (which represents the constructed list) has an initial reference count of one.  This does not change when it is assigned to <code>x</code>.  Its reference count is then increased by one on Line 7, as <code>x</code> is used in the invocation expression and <em>remains live afterward</em>.  On entry to <code>f()</code>, parameter <code>z</code> refers to Object #1, which now has reference count two. Therefore, the list assignment on Line 2 creates an entirely new object before updating it.  It also decrements the reference count of Object #1.  On Line 8, <code>x</code> still refers to Object #1 (now with reference count one) and, hence, the append is performed in place without cloning.</p>
<h2>Conclusion</h2>
<p>Reference counting is a critical optimisation to improving the performance of Whiley programs.  The latest version of the compiler (finally) supports this, although there is still room for considerable improvement.  In fact, a good starting point is the following paper:</p>
<ul>
<li>Staged Static Techniques to Efficiently Implement Array Copy Semantics in a MATLAB JIT Compiler, N. Lameed and L. Hendren.  In <em>Proceedings of the Conference on Compiler Construction</em>, 2011. [<a href="http://www.sable.mcgill.ca/mclab/mcvm/mcvmcc2011.pdf">PDF</a>]</li>
</ul>
<p>Anyway, that&#8217;s all folks!</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/12/13/efficient-value-semantics-for-whiley/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Final should be Default for Classes in Java</title>
		<link>http://whiley.org/2011/12/06/final-should-be-default-for-classes-in-java/</link>
		<comments>http://whiley.org/2011/12/06/final-should-be-default-for-classes-in-java/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 03:12:38 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3331</guid>
		<description><![CDATA[<p>We were having an interesting discussion the other day, and the issue of final classes came up.  For some reason, it suddenly occurred to me that all classes should be final by default. That is, classes should be implicitly final, rather than requiring an explicit declaration.  For example, the following should be considered invalid <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/12/06/final-should-be-default-for-classes-in-java/">Final should be Default for Classes in Java</a></span>]]></description>
			<content:encoded><![CDATA[<p>We were having an interesting discussion the other day, and the issue of <code>final</code> classes came up.  For some reason, it suddenly occurred to me <em>that all classes should be final by default</em>. That is, classes should be <em>implicitly</em> final, rather than requiring an <em>explicit</em> declaration.  For example, the following should be considered invalid in my opinion:</p>
<pre class="brush: java;">
class Parent { ... }
class Child extends Parent {... } // invalid: parent implicitly final
</pre>
<p>In place of <code>final</code> we would have another modifier, say <code>open</code>.  This would allow us to extend classes like so:</p>
<pre class="brush: java;">
open class Parent { ... }
class Child extends Parent { ... } // valid: parent explicitly open
</pre>
<p>Now, the question is: <em>why do I think final should be the default?</em> It&#8217;s got nothing to do with performance.  The following quotes from Josh Bloch&#8217;s excellent talk on API design (see [<a href="http://www.youtube.com/watch?v=aAb7hSCtvGw">1</a>][<a href="http://www.infoq.com/presentations/effective-api-design">2</a>][<a href="http://www.javaworld.com/javaworld/jw-01-2002/jw-0104-bloch.html">3</a>]) gives us a clue:</p>
<blockquote><p>&#8220;When in doubt, leave it out&#8221;</p>
<p>&#8220;You can always add, but you can never remove&#8221;</p></blockquote>
<p><em>What does this mean?</em> If you&#8217;re not sure whether a function should be included, then don&#8217;t include it.  That&#8217;s because, once you&#8217;ve included a function in a public API, people will depend upon it and you&#8217;ll have to maintain it.  If it&#8217;s badly designed, you&#8217;re stuck with it.  Sure, you can try and deprecate it &#8212; but you&#8217;ll probably end up keeping it forever anyway.</p>
<p><em>What has all this got to do with final classes?</em> Well, a non-final class can be extended of course!  Any <code>public</code> or <code>protected</code> methods can be overridden and <code>protected</code> fields read/written.   More importantly, you cannot reverse the decision &#8212; i.e. once a <code>public</code> non-final class, always a <code>public</code> non-final class.  In contrast, when using <code>final</code> as the default for classes, you can reverse your decision &#8212; i.e. you can always open, but you can never close.</p>
<p><em>This observation is hardly rocket science!</em>  Josh Bloch in his (also excellent) book <em>Effective Java</em> states<em> &#8220;you should make each class or member as inaccessible as possible&#8221;</em>.  For example, you should always prefer <code>private</code> to <code>protected</code> fields. For some reason though, he doesn&#8217;t extend this to include preferring <code>final</code> to non-<code>final</code> classes.</p>
<p>And, it looks like there are at least <a href="http://cafe.elharo.com/blogroll/final-good/">some like-minded people out there</a> and, of course, <a href="http://www.ibm.com/developerworks/java/library/j-jtp1029/index.html">there are those who think differently</a> &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/12/06/final-should-be-default-for-classes-in-java/feed/</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>Whiley v0.3.12 Released!</title>
		<link>http://whiley.org/2011/12/02/whiley-v0-3-12-released/</link>
		<comments>http://whiley.org/2011/12/02/whiley-v0-3-12-released/#comments</comments>
		<pubDate>Fri, 02 Dec 2011 03:59:03 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Ant]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Wyclipse]]></category>
		<category><![CDATA[Wyjc]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3312</guid>
		<description><![CDATA[<p>Well, crikey, what a long time since the last release.  Things haven&#8217;t changed a whole lot, apart from various bug fixes.  Probably the most interesting update is the inclusion of reference counting of compound structures to enable in-place updates and prevent unnecessary cloning.  This leads to some nice performance improvements.  Quite a bit of <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/12/02/whiley-v0-3-12-released/">Whiley v0.3.12 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>Well, crikey, what a long time since the last release.  Things haven&#8217;t changed a whole lot, apart from various bug fixes.  Probably the most interesting update is the inclusion of <em>reference counting</em> of compound structures to enable in-place updates and prevent unnecessary cloning.  This leads to some nice performance improvements.  Quite a bit of work has been done on the benchmarks as well, and also the eclipse plugin.</p>
<h2>ChangeLog</h2>
<ul>
<li>Added support for proper reference counting of compound structures.  This employs a live variables analysis to determine when a local variable is dead.</li>
<li>Reworked the name resolution and module loading system.  This was done primarily to support build tools such as ant and eclipse.</li>
<li>Improved the Ant task.</li>
<li>Further improved the runtime checking of constraints.</li>
<li>Added some rudimentary reporting of memory usage by the various compiler stages.</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.12.tgz" title="Download wdk-src-v0.3.12">wdk-src-v0.3.12</a><br />
      Created on December 2, 2011.  66 Downloads, 2.1 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.12.jar" title="Download wyjc-v0.3.12.jar">wyjc-v0.3.12.jar</a><br />
      Created on December 2, 2011.  71 Downloads, 1.0 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/bench/wybench-v0.1.5.tgz" title="Download wybench-v0.1.5">wybench-v0.1.5</a><br />
      Created on December 2, 2011.  51 Downloads, 5.8 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/12/02/whiley-v0-3-12-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Not all Tests are Passing &#8230; is that so Bad?</title>
		<link>http://whiley.org/2011/11/01/not-all-tests-are-passing-is-that-so-bad/</link>
		<comments>http://whiley.org/2011/11/01/not-all-tests-are-passing-is-that-so-bad/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 20:11:30 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3302</guid>
		<description><![CDATA[<p>For the Whiley compiler, I currently have over 500 end-end tests and in excess of 15,000 unit tests (most of which were auto-generated and target the type system).  Each end-end test is a short Whiley program that is  categorised as either valid or invalid.  Valid tests also include sample output and are expected to <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/11/01/not-all-tests-are-passing-is-that-so-bad/">Not all Tests are Passing &#8230; is that so Bad?</a></span>]]></description>
			<content:encoded><![CDATA[<p>For the Whiley compiler, I currently have over 500 end-end tests and in excess of 15,000 unit tests (most of which were auto-generated and target the type system).  Each end-end test is a short Whiley program that is  categorised as either <em>valid</em> or <em>invalid</em>.  Valid tests also include sample output and are expected to compile, execute and produce matching output.  The invalid tests are expected to generate a compile-time error.  To make this more precise, I categorise the kinds of error that the compiler can produce as:<em> internal failure</em>, <em>syntax error</em> or <em>verification error</em>.  Every invalid test is specified to raise either a syntax error or a verification error, and the test will not pass if the compiler does anything else.  Thus, an invalid test which should produce a syntax error will not pass if the compiler barfs out a <code>NullPointerException</code>.</p>
<p>Now, the thing is: <em>not all my end-end tests are currently passing</em>.  In fact, I don&#8217;t think it&#8217;s <em>ever been the case that all of the tests have passed</em>.  That may seem like a bad thing, but I think there are some mitigating circumstances:</p>
<ol>
<li>My test suite is constantly growing.  As soon as I spot an error, or think of a possible problem, I add a test.  Adding tests makes me feel good, and I love it!  That&#8217;s because a test is a piece of knowledge <em>locked-in</em>.  Once the test is written and checked in, <em>I can&#8217;t forget</em>.</li>
<li>Some failures represent issues that I&#8217;ve given very low priority to.  Eventually, I will get to them &#8230; but not yet.  I do sometimes make use of the <code>@Ignore</code> annotation for these kinds of tests.</li>
<li>Some failures represent significant design flaws in the system.  They should be high-priority, but represent weeks or months of refactoring and redesigning to fix.  I don&#8217;t like to <code>@Ignore</code> these ones &#8230; I prefer to feel the pain.</li>
</ol>
<p>In a way, my test suite is like a queue.  My tests never all pass because by the time I fixed all the ones that are failing &#8230; <em>I&#8217;ve added some more</em>!</p>
<p>This is similar to <a href="http://en.wikipedia.org/wiki/Test-driven development" target="_top" >Test-driven development</a> I suppose.  What I don&#8217;t like about TDD though, is that you&#8217;re supposed to write a test and then immediately make it pass.  That doesn&#8217;t work for me since,  in a few seconds, I can write a test that might takes months of careful refactoring to solve.   I&#8217;m never going to fix those ones immediately &#8230; they need serious <a href="http://blip.tv/clojure/hammock-driven-development-4475586">hammock time</a>!</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/11/01/not-all-tests-are-passing-is-that-so-bad/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Whiley v0.3.11 Released!</title>
		<link>http://whiley.org/2011/10/28/whiley-v0-3-11-released/</link>
		<comments>http://whiley.org/2011/10/28/whiley-v0-3-11-released/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 00:40:09 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Wyjc]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3224</guid>
		<description><![CDATA[<p>As usual, it&#8217;s been a surprising amount of effort &#8230; but the next release of Whiley is available!  It&#8217;s been quite a long time since the last update, but then quite a lot has improved.  Unfortunately, I did find a fairly serious problem with my type system, which means I&#8217;ve got to go back <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/10/28/whiley-v0-3-11-released/">Whiley v0.3.11 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>As usual, it&#8217;s been a surprising amount of effort &#8230; but the next release of Whiley is available!  It&#8217;s been quite a long time since the last update, but then quite a lot has improved.  Unfortunately, I did find a fairly serious problem with my type system, which means I&#8217;ve got to go back to the drawing board and figure out how to fix it.</p>
<h2>ChangeLog</h2>
<ul>
<li>Fixed support for line numbers in classfiles (this required adding dead-code elimination phase at the WYIL level)</li>
<li>Added a generic class for handling error messages.  The aim here is improve the quality and consistency of error message reporting, by providing a central class which is responsible for this.  However, this is in its infancy and a lot remains to be done here.</li>
<li>Improved Compiler Documentation.</li>
<li>Added support for parsing and checking throws clauses.  This require extending the function and method types to include another slot for the throws clause, which behaves much like that for return values.</li>
<li>Added support for checking that catch handlers are not dead-code.  That is, every catch handler must be able to catch something in the try-catch block.</li>
<li>Added support for the <code>native</code> modifier on functions/methods.  This indicates that the given method is implemented as a native Java method.  Under-the-hood, such methods are redirected into a class of the same package and name (but with &#8220;$native&#8221; appended to the name).</li>
<li>Added support for the <code>export</code> modifier on functions/methods.  This tells the compiler that the function or method in question is intended to be called by some external (i.e. native Java) code.  Thus, the compiler omits the usual name mangling it would apply.</li>
<li>Added support for passing modifiers (including native and public) through into the WYIL (which was surprisingly absent).</li>
<li>Changed the way cases of a switch statement work.  Now, you can no longer &#8220;<a href="http://whiley.org/2011/10/26/fall-through-by-default-switch-statements/">fall-through by default</a>&#8220;.</li>
<li>Removed the implicit coercion from <code>char</code> to <code>int</code>, which really didn&#8217;t make sense.  You can still force this coercion using an explicit cast.</li>
<li>Added some more methods to the core standard library.</li>
<li>Added support for testing the length of a dictionary.</li>
<li>Added <code>do</code> &#8211; <code>while</code> statement.</li>
<li>Fixed a lot of bugs!</li>
</ul>
<h2>Future Work</h2>
<ul>
<li>Fix the problem with type difference, where currently <code>[int] - [int] =&gt; [void]</code></li>
<li>Back propagation doesn&#8217;t work properly for try-catch blocks</li>
<li>Back propagation doesn&#8217;t work through pre-/post-conditions and loop invariants.</li>
<li>Many of the type constraints are not expanded properly.</li>
<li>Include support for e.g. <em>effective</em> list types, etc.</li>
<li>There is currently no way to determine if when a dictionary contains a particular key.</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.11.tgz" title="Download wdk-src-v0.3.11">wdk-src-v0.3.11</a><br />
      Created on October 28, 2011.  85 Downloads, 2.1 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.11.jar" title="Download wyjc-v0.3.11.jar">wyjc-v0.3.11.jar</a><br />
      Created on October 28, 2011.  95 Downloads, 1.0 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/10/28/whiley-v0-3-11-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fall-Through by Default for Switch Statements?</title>
		<link>http://whiley.org/2011/10/26/fall-through-by-default-switch-statements/</link>
		<comments>http://whiley.org/2011/10/26/fall-through-by-default-switch-statements/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 20:41:14 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3255</guid>
		<description><![CDATA[<p>The switch statement has a long history, and most languages support it or something similar.  In my experience, I found it to be very useful &#8212; both for conciseness, and also improving performance.  With the recent release of Java 7, you can finally switch over strings.</p> <p>In Whiley, the syntax for switch statements currently <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/10/26/fall-through-by-default-switch-statements/">Fall-Through by Default for Switch Statements?</a></span>]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://en.wikipedia.org/wiki/Switch_statement">switch statement</a> has a long history, and most languages support it or something similar.  In my experience, I found it to be very useful &#8212; both for conciseness, and also improving performance.  With the recent release of Java 7, you can finally <a href="http://code.joejag.com/2009/new-language-features-in-java-7/">switch over strings</a>.</p>
<p>In Whiley, the syntax for switch statements currently looks like this:</p>
<pre class="brush: whiley;">
for token in modifiers:
    modifier = null
    switch token.id:
       case &quot;PUBLIC&quot;:
       case &quot;public&quot;:
          modifier = ACC_PUBLIC
          break
       case &quot;FINAL&quot;:
       case &quot;final&quot;:
          modifier = ACC_FINAL
          break
       ...
       default:
          throw SyntaxError(&quot;invalid modifier&quot;,token)
</pre>
<p>(This excerpt is based on my <a href="https://github.com/DavePearce/wybench/tree/master/sequential/macro/jasm">Java Assembler/Disassembler</a> benchmark)</p>
<p>Now, I&#8217;m having something of a dilemma over this syntax: <em>should I support fall-through case statements or not?</em></p>
<p>As you can see from above, my initial reaction was: <em>yes</em>.  But, I&#8217;m starting to think this is a really bad idea and there are a few reasons:</p>
<ol>
<li>Obviously, fall-through by default is dangerous as its easy to forget the <code>break</code>.  I&#8217;ve already done this a few times!</li>
<li>Generally, I think fall-through is the exception, not the rule.  That is,  most cases do require the <code>break</code> and, hence, fall-through by default causes additional verbosity.</li>
<li>The overloaded <code>break</code> statement can be annoying when you actually want to break out of a loop.</li>
</ol>
<p>Now, of course, I&#8217;m not the first to think along these lines (see e.g. <a href="http://c2.com/cgi/wiki?IsBreakStatementArchaic">[1]</a><a href="http://stackoverflow.com/questions/188461/switch-statement-fallthrough-should-it-be-allowed">[2]</a><a href="http://javascript.crockford.com/code.html">[3]</a>) and, in fact, I&#8217;m probably being a bit slow on the uptake here!</p>
<p>Several languages (e.g. <a href="http://en.wikipedia.org/wiki/Go_%28programming_language%29">Go</a>, <a href="http://jashkenas.github.com/coffee-script/#switch">CoffeeScript</a>, <a href="http://en.wikipedia.org/wiki/Switch_statement#Pascal">Pascal</a>) do not support fall-through by default. For example, Go supports an explicit <code>fallthrough</code> statement, which might look something like this in Whiley:</p>
<pre class="brush: whiley;">
for token in modifiers:
    modifier = null
    switch token.id:
       case &quot;PUBLIC&quot;:
          fallthrough
       case &quot;public&quot;:
          modifier = ACC_PUBLIC
       case &quot;FINAL&quot;:
          fallthrough
       case &quot;final&quot;:
          modifier = ACC_FINAL
       ...
       default:
          throw SyntaxError(&quot;invalid modifier&quot;,token)
</pre>
<p>Go is quite interesting as it provides <a href="http://golangtutorials.blogspot.com/2011/06/control-structures-go-switch-case.html">multi-match case statements</a> as well, which might look like something like this in Whiley:</p>
<pre class="brush: whiley;">
for token in modifiers:
    modifier = null
    switch token.id:
       case &quot;PUBLIC&quot;,&quot;public&quot;:
          modifier = ACC_PUBLIC
       case &quot;FINAL&quot;,&quot;final&quot;:
          modifier = ACC_FINAL
       ...
       default:
          throw SyntaxError(&quot;invalid modifier&quot;,token)
</pre>
<p>I really like this syntax (which I think is <a href="http://en.wikipedia.org/wiki/Switch_statement#Pascal">originally from Pascal)</a>.  In Pascal, you can provide ranges as well which certainly makes sense.</p>
<p>So, all things considered, I&#8217;m convinced it is a mistake to support fall-through by default in Whiley.  Fortunately, it&#8217;s not too late for me to correct this!</p>
<p>The <strong>big question</strong> then is: <em>do I support explicit fallthrough, multi-match cases or both?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/10/26/fall-through-by-default-switch-statements/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>What Kind of Revert are You?</title>
		<link>http://whiley.org/2011/10/19/what-kind-of-revert-are-you/</link>
		<comments>http://whiley.org/2011/10/19/what-kind-of-revert-are-you/#comments</comments>
		<pubDate>Tue, 18 Oct 2011 20:35:04 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Other]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3231</guid>
		<description><![CDATA[<p>Reverting is tough.  There&#8217;s no doubt about it!  I don&#8217;t mean tough as in technically challenging &#8212; no, version control systems make this easy!  I mean tough as in mentally challenging.  You&#8217;re faced with days or weeks of effort going down the drain, and you have to decide when to pull the plug.  Sure, <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/10/19/what-kind-of-revert-are-you/">What Kind of Revert are You?</a></span>]]></description>
			<content:encoded><![CDATA[<p>Reverting is tough.  There&#8217;s no doubt about it!  I don&#8217;t mean tough as in <em>technically challenging</em> &#8212; no, version control systems make this easy!  I mean tough as in <em>mentally challenging</em>.  You&#8217;re faced with days or weeks of effort going down the drain, and you have to decide when to pull the plug.  Sure, it&#8217;ll still be in your history somewhere.  But, you&#8217;ll probably never get it out again.  And, if you do, it won&#8217;t integrate with the latest version as this is constantly marching on.</p>
<p>At some point though, you know it&#8217;s time.  You made a bad call, and you need to undo that and get back on track. It seems there are few different way to end up in this situation:</p>
<ol>
<li><strong>The Obvious Disaster.</strong> Perhaps this is the most common case.  You have an idea and start pushing it through.  But, after a while, it becomes obvious <em>it will never work</em>.  If you&#8217;d thought a bit harder up front, you&#8217;d probably have realised this.  Normally, not too much time is wasted.</li>
<li><strong>The Winding Road.</strong> This one is ugly.  You&#8217;ve had an idea which, unbeknown to you, is fatally flawed.  The unfortunate thing is that the reason behind the flaw is very, very subtle.  It&#8217;s only after a fairly significant amount of effort that you (finally) realise: <em>this approach can&#8217;t work</em>.  This costs serious time, and is fustrating at best.  For me, I try not to lose to much sleep over these ones &#8212; they come with the territory.</li>
<li><strong>The Good Idea. </strong> This one is even uglier!  You&#8217;ve had an idea <em>which will actually work</em>.  The problem is, it&#8217;s going to take a significant amount of effort to push through.  Furthermore, the gains from the improvement maybe somewhat marginal.  You&#8217;re completely paralysed: undo the work so far and waste what is a good idea simply because it&#8217;s going to take weeks or months to finish; OR, stubbornly keep going and push the damn thing through anyway.  I hate these ones, since I don&#8217;t like knowly going backwards.  These ones I lose lots of sleep over.</li>
<li><strong>The Ping Pong</strong>.   This is where you revert, and then realise actually maybe you should have stuck with it.  So you undo the revert!  Then, maybe, you realise why you reverted in the first place and revert again, and so on.  I think experience makes you aware of this cycle, and helps you avoid it by forcing you to think carefully before reverting.</li>
</ol>
<p>So, the question right now as I stare at my code is: <em>what kind of revert are you?</em></p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/10/19/what-kind-of-revert-are-you/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whiley Gets Funding!</title>
		<link>http://whiley.org/2011/10/12/whiley-gets-funding/</link>
		<comments>http://whiley.org/2011/10/12/whiley-gets-funding/#comments</comments>
		<pubDate>Tue, 11 Oct 2011 21:00:59 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Interest]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3207</guid>
		<description><![CDATA[<p>I&#8217;m pretty excited to announce that I have been awarded a prestigious Marsden Grant to support research on the Whiley project over the next three years.  This is obviously great news for Whiley, and will go a long way towards making the project a reality.  The following Dom Post article covered the recent announcement <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/10/12/whiley-gets-funding/">Whiley Gets Funding!</a></span>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pretty excited to announce that I have been awarded a prestigious <a href="http://www.royalsociety.org.nz/programmes/funds/marsden/">Marsden Grant</a> to support research on the Whiley project over the next three years.  This is obviously great news for Whiley, and will go a long way towards making the project a reality.  The following Dom Post article covered the recent announcement of awards (although my project doesn&#8217;t get a specific mention):</p>
<p><a href="http://whiley.org/wp-content/uploads/2011/10/DomPostMarden.png"><img class="aligncenter size-full wp-image-3210" title="DomPostMarden" src="http://whiley.org/wp-content/uploads/2011/10/DomPostMarden.png" alt="" width="400" height="300" /></a></p>
<p>Some more information about the awarded grants is available <a href="http://www.royalsociety.org.nz/programmes/funds/marsden/awards/2011/">here</a> as well.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/10/12/whiley-gets-funding/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Whiley v0.3.10 Released!</title>
		<link>http://whiley.org/2011/09/21/whiley-v0-3-10-released/</link>
		<comments>http://whiley.org/2011/09/21/whiley-v0-3-10-released/#comments</comments>
		<pubDate>Wed, 21 Sep 2011 00:11:59 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Types]]></category>
		<category><![CDATA[Typing]]></category>
		<category><![CDATA[Wyjc]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3033</guid>
		<description><![CDATA[<p>Well, it&#8217;s been a tough slog.  But, finally, we have a new release of Whiley!!  The main thing that&#8217;s improved over the past few weeks is the underlying type implementation.  This was causing problems before, as programs which should type-check were failing and vice-versa.  To resolve this, the type system has been reimplemented from <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/09/21/whiley-v0-3-10-released/">Whiley v0.3.10 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>Well, it&#8217;s been a tough slog.  But, finally, we have a new release of Whiley!!  The main thing that&#8217;s improved over the past few weeks is the underlying type implementation.  This was causing problems before, as programs which should type-check were failing and vice-versa.  To resolve this, the type system has been reimplemented from scratch and (hopefully) it should be significantly better.  In particular, I&#8217;ve done quite a lot more testing (e.g. I now have around 15,000 individual unit tests for the <code>Type</code> class).</p>
<p>The other main difference is the way in which <code>import</code> statements are handled.  Whilst this is definitely a step in the right direction, it&#8217;s not without some outstanding issues &#8212; which I discussed in more detail <a href="http://whiley.org/2011/09/03/namespaces-in-whiley/">here</a>.</p>
<h2>ChangeLog</h2>
<ul>
<li>Changed the way imports are interpreted.  Previously, <code>import whiley.lang.String</code> would have imported all symbols from module <code>String</code>.  Now, it only imports the module name.  So, for example, to access the method <code>indexOf</code>, you need to write <code>String.indexOf(s,i)</code>.  However, you can still replicate the old approach by directly importing the names from a module.  For example, <code>import * from whiley.lang.String</code> imports all names from the <code>String</code> module</li>
<li>The entry point <code>main()</code> no longer has <code>System</code> as its receiver.  Instead, <code>System</code> is a parameter and <code>main</code> is a headless method.  This is necessary as, otherwise, the <code>System</code> process is blocked until main completes!</li>
<li>Split out the type system into a separate library called wyautl.  As part of this, I&#8217;ve essentially reimplemented the type system from scratch in an effort to really harden it up.  I&#8217;ve done a significant amount of testing, and it&#8217;s definitely a lot better.  The type system now directly supports <em>negation</em> and <em>intersection</em> types, which makes for some interesting possibilities.</li>
<li>Support for dictionaries is somewhat improved.  In particular, you can now create an empty dictionary!  An empty dictionary is denoted <code>{-&gt;}</code> (contrasting with <code>{}</code> for sets and <code>[]</code> for lists).</li>
<li>Support for try-catch blocks has been added (finally).  This means you can now catch exceptions in Whiley.  At the moment, however, the system does not check that you properly declare your exceptions &#8230; but that will come shortly.</li>
<li>Improved the JavaDoc documentation for the compiler.  I plan to make this documentation visible soon, in conjunction with detailed discussion of how the compiler actually works.</li>
<li>Various bug fixes.</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.10.tgz" title="Download wdk-src-v0.3.10">wdk-src-v0.3.10</a><br />
      Created on September 21, 2011.  80 Downloads, 2.0 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.10.jar" title="Download wyjc-v0.3.10">wyjc-v0.3.10</a><br />
      Created on September 21, 2011.  95 Downloads, 956.0 KB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/09/21/whiley-v0-3-10-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Whiley Automata Library (WYAUTL)</title>
		<link>http://whiley.org/2011/09/20/the-whiley-automata-library-wyautl/</link>
		<comments>http://whiley.org/2011/09/20/the-whiley-automata-library-wyautl/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 00:51:54 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Structural Subtyping]]></category>
		<category><![CDATA[Tree Automata]]></category>
		<category><![CDATA[Types]]></category>
		<category><![CDATA[Wyautl]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3139</guid>
		<description><![CDATA[<p>As part of the upcoming v0.3.10 release of Whiley, I&#8217;ve invested considerable effort reimplementing the type system.  This was necessary because, whilst my old implementation generally worked, writing larger programs exposed a lot of issues.  The most interesting aspect of this process is the development of a general-purpose library for representing and manipulating tree <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/09/20/the-whiley-automata-library-wyautl/">The Whiley Automata Library (WYAUTL)</a></span>]]></description>
			<content:encoded><![CDATA[<p>As part of the upcoming v0.3.10 release of Whiley, I&#8217;ve invested considerable effort reimplementing the type system.  This was necessary because, whilst my old implementation generally worked, writing larger programs exposed a lot of issues.  The most interesting aspect of this process is the development of a general-purpose library for representing and manipulating <a href="http://whiley.org/2011/07/06/regular-tree-automata/">tree automatas</a>.</p>
<h2>Tree Automata</h2>
<p>A tree automaton in WYAUTL is a directed graph where edges may have labels.  In general, the nodes of this graph are called <em>states</em>, whilst the edges are called <em>transitions</em>.  States have the following properties:</p>
<ul>
<li><strong>Kind</strong>.  Every state has a &#8220;kind&#8221;, which tells us something about it.  States with the same kind are somehow related and should be treated in the same way.  In Whiley, each distinct category of type has its own kind.  For example, <code>void</code>, <code>any</code> and <code>null</code> are distinct kinds.</li>
<li><strong>Children.</strong> Every state has zero or more children.  Essentially, the children of a state are those states directly reachable in a single transition.</li>
<li><strong>Determinism.</strong> Every state is either <em>deterministic</em> or <em>non-deterministic</em>.  This choice affects the way states are treated within the various algorithms.  Essentially, in a non-deterministic state, there is no fixed ordering of children.  In a deterministic state, every child is in a fixed position and can only accepts inputs in that position (more on this later).</li>
<li><strong>Supplementary Data.</strong> A state may additionally have some supplementary data.  This is specific to the problem domain the automata are used for.  In Whiley, for example, states corresponding to records have supplementary data to store field names.</li>
</ul>
<p>A tree automaton <em>accepts</em> matching <em>input trees</em>.  An input tree is essentially an acyclic automaton (generally speaking a tree, although it doesn&#8217;t actually need to be).   Tree states have kinds, children and (optionally) supplementary data.  However, tree states are always deterministic.  The intuition is that an automaton state matches a tree state if they have the same kind, and their children match as well.  The issue of determinism and supplementary data make this picture slightly more complicated, however.</p>
<h2>Example</h2>
<p>To begin with, I&#8217;ll consider an entirely abstract example.  This is because the automata library can represent arbitrary tree automata, not just those needed to for types in Whiley.  Then, we&#8217;ll see how this translates into the underlying representation of types in Whiley.</p>
<p><a href="http://whiley.org/wp-content/uploads/2011/09/TreeAutomata.png"><img class="aligncenter size-full wp-image-3157" style="border: 0pt none;" title="TreeAutomata" src="http://whiley.org/wp-content/uploads/2011/09/TreeAutomata.png" alt="" width="538" height="322" /></a>In this example, we have a single automaton on the left, and three matching tree inputs on the right.  In the automaton, square nodes indicate deterministic states, whilst circles indicate non-deterministic states.  The kind of a state is given by its colour.  We can see, for the deterministic states, that every transition is given a numeric label.  This indicates the &#8220;position&#8221; of that transition and, for simplicity, can be thought of as an edge label.  In the tree inputs, every node is deterministic and, hence, all transitions are labelled.</p>
<p>In the above example, a deterministic state in the automaton matches a state in an input tree if they have the same kind, and each child matches the corresponding child in the input.  For the non-deterministic states, however, it&#8217;s sufficient that, for every child state of the input, there exists a matching child state in the automaton.</p>
<h2>Back to Types</h2>
<p style="text-align: left;">Types in Whiley are represented using tree automata.  In fact, if you look at my previous posts on the algorithmic aspects of implementing types in Whiley  (see e.g. <a href="http://whiley.org/2011/08/30/simplification-vs-minimisation-of-types-in-whiley/">here</a>, <a href="http://whiley.org/2011/03/07/implementing-structural-types/">here</a> and <a href="http://whiley.org/2011/02/16/minimising-recursive-data-types/">here</a>) you&#8217;ll notice a striking resemblance with the above diagrams.  That&#8217;s because, well, they&#8217;re essentially the same.  Take, for example, the following Whiley type:</p>
<pre class="brush: whiley;">
define Tree as null | {int data, Tree left, Tree right}
</pre>
<p>The above type can be represented as a tree automaton, like so:</p>
<p><a href="http://whiley.org/wp-content/uploads/2011/09/TreeAutomata2.png"><img class="aligncenter size-full wp-image-3170" style="border: 0pt none;" title="TreeAutomata2" src="http://whiley.org/wp-content/uploads/2011/09/TreeAutomata2.png" alt="" width="529" height="254" /></a></p>
<p>Here, grey states represent <code>null</code>, yellow states represent <code>int</code>, blue states represent <code>records</code> (i.e. <code>{ ... }</code>) and green states unions (i.e. <code>... | ...</code>).  Furthermore, the rules for accepting inputs are adjusted so non-determinstic states do not themselves need to match a corresponding state in the input (although their children still do).  The latter is made possible in the library because one can extend the &#8220;default interpretation&#8221; of automata.</p>
<h2>Conclusion</h2>
<p>Overall, implementing a general purpose automata library has proved successful in reducing complexity of the Whiley compiler.  This is because the library abstracts many of the key differences between types, and handles various issues such as <em>minimisation</em> and <em>canonicalisation</em> automatically. The library can also be developed and tested in isolation, making it easier to focus on without getting distracted by Whiley specifics.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/09/20/the-whiley-automata-library-wyautl/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Namespaces in Whiley</title>
		<link>http://whiley.org/2011/09/03/namespaces-in-whiley/</link>
		<comments>http://whiley.org/2011/09/03/namespaces-in-whiley/#comments</comments>
		<pubDate>Sat, 03 Sep 2011 00:34:20 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3090</guid>
		<description><![CDATA[<p>With the upcoming v0.3.10 release of Whiley, the way import statements are interpreted has changed in a fairly significant manner.  The primary purpose of this is to give better support for namespaces. The following illustrates what&#8217;s changed:</p> import whiley.lang.Math bool check(int x, int y): return max(x,y) == x <p>Previously, the above code would compile <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/09/03/namespaces-in-whiley/">Namespaces in Whiley</a></span>]]></description>
			<content:encoded><![CDATA[<p>With the upcoming v0.3.10 release of Whiley, the way <code>import</code> statements are interpreted has changed in a fairly significant manner.  The primary purpose of this is to give better support for <a href="http://en.wikipedia.org/wiki/Namespace (computer science)" target="_top" >namespaces</a>. The following illustrates what&#8217;s changed:</p>
<pre class="brush: whiley;">
import whiley.lang.Math

bool check(int x, int y):
    return max(x,y) == x
</pre>
<p>Previously, the above code would compile with function <code>max()</code> being imported from <code>whiley.lang.Math</code>.  In other words, an <code>import</code> statement automatically imports all names from a given module.  However, this gives relatively little control over namespaces and quickly leads to <a href="http://bytebaker.com/2008/07/30/python-namespaces/">namespace pollution</a>.</p>
<p>Therefore, in the upcoming release of Whiley, the semantics of <code>import</code> statements has been brought more in line with <a href="http://en.wikipedia.org/wiki/Python (programming language)" target="_top" >Python</a>.  Thus, the above would not compile as is.  Instead, we would need to write:</p>
<pre class="brush: whiley;">
import whiley.lang.Math

bool check(int x, int y):
    return Math.max(x,y) == x
</pre>
<p>This all makes sense, and I&#8217;m absolutely happy with the choice to do this.  However, as usual, there are some hidden issues I didn&#8217;t foresee.</p>
<h2>Root Concepts</h2>
<p>The first issue with the above change came out from actually writing code using it!  In particular, I was working on my bytecode disassembler benchmark and constructed a module <code>ClassFile</code> as follows:</p>
<pre class="brush: whiley;">
define ClassFile as ...
define Reader as ...
define Writer as ...
</pre>
<p>This gives rise to the types <code>ClassFile.Reader</code> and <code>ClassFile.Writer</code>, both of which make sense.  But, it also gives rise to the type <code>ClassFile.ClassFile</code>, which frankly is rather cumbersome.  That&#8217;s because a <code>ClassFile</code> is both a key concept in my design and, coincidently, a namespace as well.  Of course, I could prossibly rename <code>ClassFile</code> to be module <code>Class</code> as follows:</p>
<pre class="brush: whiley;">
define File as ...
define Reader as ...
define Writer as ...
</pre>
<p>This gives rise to the types <code>Class.Reader</code>, <code>Class.Writer</code> and <code>Class.File</code>.  This is better, but I suspect such renaming won&#8217;t always fit well with the top-level design of a program.  I imagine Python must suffer from this problem as well, so I&#8217;ll have to look into it more &#8230;</p>
<h2>Processes and Messages</h2>
<p>Another problem with the above change to <code>import</code> statements, is how it affects process messages.  The following illustrates:</p>
<pre class="brush: whiley;">
import whiley.io.File

[byte] ::readFile(String filename):
    fr = File.Reader(filename)
    return fr.read()
</pre>
<p>This all looks fairly sensible, right?  Well, currently, it doesn&#8217;t compile.  The reason becomes apparent if we look inside the <code>File</code> module:</p>
<pre class="brush: whiley;">
package whiley.io

define Reader as process { ... }

Reader ::Reader(String filename):
    return spawn { ... }

[byte] Reader::read():
     ...
</pre>
<p>What we see is that <code>read()</code> is a message declared on process type <code>File.Reader</code>.  In Java terms, <code>read()</code> is a <code>static</code> method which accepts an argument of type <code>File.Reader</code>.  And, therein lies the problem.  To get our <code>readFile()</code> example to compile we need to write this:</p>
<pre class="brush: whiley;">
import whiley.io.File

[byte] ::readFile(String filename):
    fr = File.Reader(filename)
    return fr.(File.read)()
</pre>
<p>Or, alternatively, we could write it as this:</p>
<pre class="brush: whiley;">
import whiley.io.File
import read from whiley.io.File

[byte] ::readFile(String filename):
    fr = File.Reader(filename)
    return fr.read()
</pre>
<p>I find this somewhat annoying.  However, it&#8217;s not clear how much of a problem it really is.  That&#8217;s because, in practice, we&#8217;d probably want to define <code>File.Reader</code> as an <code>interface</code> like so:</p>
<pre class="brush: whiley;">
package whiley.io

define Reader as interface { [byte] read() }

Reader ::Reader(String filename):
    proc = spawn { ... }
    return { this: proc, read: &amp;read }

[byte] Reader::read():
     ...
</pre>
<p>An <code>interface</code> is a special kind of record with an explicit field <code>this</code>.  Then, when we access the field <code>read</code>, <code>this</code> is automatically used as the receiver.  With <code>Reader</code> implemented as above, our original incantation of <code>readFile()</code> would actually compile.  That&#8217;s because, in this case, <code>fr.read()</code> corresponds to an <em>indirect message send</em>, where as before it was a <em>direct message send</em>.</p>
<p>On the whole, I&#8217;m not sure what I&#8217;m complaining about!  Implementing <code>Reader</code> as an <code>interface</code> versus a <code>process</code> is much of a muchness.  There is a minor issue of performance as, for a process you get a static method invocation.  But, I&#8217;m probably just splitting hairs &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/09/03/namespaces-in-whiley/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Simplification vs Minimisation of Types in Whiley</title>
		<link>http://whiley.org/2011/08/30/simplification-vs-minimisation-of-types-in-whiley/</link>
		<comments>http://whiley.org/2011/08/30/simplification-vs-minimisation-of-types-in-whiley/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 22:19:09 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Structural Subtyping]]></category>
		<category><![CDATA[Theory]]></category>
		<category><![CDATA[Types]]></category>
		<category><![CDATA[Typing]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3055</guid>
		<description><![CDATA[<p>Recently, I&#8217;ve been trying to harden up the implementation of Whiley&#8217;s type system. The reason for this is fairly straightforward: bugs in the code often prevent me from compiling correct programs!</p> <p>In thinking about how to restructure the algorithms I&#8217;m using, I realised its important to distinguish simplification from minimisation.  I&#8217;ve talked about minimisation <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/08/30/simplification-vs-minimisation-of-types-in-whiley/">Simplification vs Minimisation of Types in Whiley</a></span>]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve been trying to harden up the implementation of Whiley&#8217;s type system.  The reason for this is fairly straightforward: <em>bugs in the code often prevent me from compiling correct programs!</em></p>
<p>In thinking about how to restructure the algorithms I&#8217;m using, I realised its important to distinguish <em>simplification</em> from <em>minimisation</em>.  I&#8217;ve talked about minimisation in some detail before (see <a href="http://whiley.org/2011/02/16/minimising-recursive-data-types/">here</a> and <a href="http://whiley.org/2011/03/07/implementing-structural-types/">here</a>).</p>
<p>In fact, there are three phases in computing the ideal representation of a given type (in order of increasing difficulty):</p>
<ul>
<li><strong>Simplification.</strong> Here, we apply mostly straightforward simplifications.  Examples include: <code>(T|T) =&gt; T</code>, <code>(T|any) =&gt; any</code>, <code>(T|void) =&gt; T</code>, <code>(T|(S|U)) =&gt; (T|S|U)</code>, etc.</li>
</ul>
<ul>
<li><strong>Minimisation. </strong>Here, we ensure that no two nodes in the type graph are <em>equivalent</em> under the subtyping operator.  For example, the type <code>X&lt;[null|[null|X]]&gt;</code> is not minimised, whilst <code>X&lt;[null|X]&gt;</code> is its minimised form.</li>
</ul>
<ul>
<li><strong>Canonicalisation.</strong> The final step is to ensure equivalent types have an identical representation on the machine.  This is related to the <a href="http://en.wikipedia.org/wiki/Graph isomorphism" target="_top" >Graph isomorphism</a> problem and, more specifically, the issues of computing a <a href="http://en.wikipedia.org/wiki/Graph canonization" target="_top" >canonical form</a> of a graph.</li>
</ul>
<p>This all seems fairly straightforward &#8230; but there are of course some tricky bits!!</p>
<h2>Simplification is not that Simple!</h2>
<p>The first mistake I made was to assume that simplification was a simple step in the process.  Unfortunately, there are some gotchas:</p>
<pre class="brush: whiley;">
define LinkedList as null | { LinkedList next, int data }
define MyList as int | LinkedList
</pre>
<p>The problem is how to minimise this.  One property I want of the simplified form is to eliminate unions of unions.  But, consider the type graph for <code>MyList</code>:</p>
<p style="text-align: center;"><a href="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes1.png"><img class="aligncenter size-full wp-image-3065" style="border: 0pt none;" title="SimplifyingRecursiveTypes1" src="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes1.png" alt="" width="194" height="237" /></a></p>
<p>(here, circles represent unions, squares represent records, etc)</p>
<p>Now, it&#8217;s difficult to see how we simplify the above to remove the union (node <code>0</code>) of a union (node <code>2</code>).  That&#8217;s because of the recursive link directly into node <code>2</code>.  In fact, we can achieve this by judiciously expanding the type like so:</p>
<p><a href="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes2.png"><img class="aligncenter size-full wp-image-3068" style="border: 0pt none;" title="SimplifyingRecursiveTypes2" src="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes2.png" alt="" width="226" height="306" /></a>This does the trick and (I believe) it&#8217;s always possible to eliminate unions of unions in this way.</p>
<h2>Simplification Helps Minimisation!</h2>
<p>You might be wondering: <em>why bother with simplification at all? </em> Well, it&#8217;s because it simplifies the minimisation algorithm (which is one of the components that features a lot of bugs).  In essence, simplification gives me the following property:</p>
<blockquote><p><strong>Property 1</strong>.  Any two equivalent nodes in a simplified type have identical reachable structure.</p></blockquote>
<p>In a non-simplified type graph, the above is clearly not true.  For example, in the type <code>(any|int)</code> the outer union and <code>any</code> are equivalent (but have different structure).  Here&#8217;s another example:</p>
<p style="text-align: center;"><a href="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes3.png"><img class="aligncenter size-full wp-image-3070" style="border: 0pt none;" title="SimplifyingRecursiveTypes3" src="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes3.png" alt="" width="230" height="159" /></a></p>
<p>Here, nodes <code>0</code>, <code>1</code> and <code>2</code> are all equivalent.  But, whilst nodes <code>1</code> and <code>2</code> have identical reachable structure, this differs from node <code>0</code>.  In particular, the children of node <code>0</code> are in the same equivalence class as node <code>0</code>, whilst those for nodes <code>1</code> and <code>2</code> are not.  In practical terms, my minimisation algorithm would have to handle this edge case and its numerous variations.  With simplified form, however, these awkward cases disappear.</p>
<h2>Minimised is Simplified?</h2>
<p>An interesting question is whether a type remains in simplified form after minimisation.  I conjecture that the answer is yes!  Atleast, provided a little care is taken.</p>
<p>The main issue is that the minimisation process can remove union nodes; however, <em>it cannot introduce them</em>.  Consider this final example:</p>
<pre class="brush: whiley;">
define LinkedList as null | { LinkedList next, int data }
define InnerList as null | { OuterList next, int data }
define OuterList as null | { InnerList next, int data }
define MyList as LinkedList | OuterList
</pre>
<p>These definitions give rise to the following type graph for <code>MyList</code>:</p>
<p style="text-align: center;"><a href="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes23.png"><img class="aligncenter size-full wp-image-3077" style="border: 0pt none;" title="SimplifyingRecursiveTypes23" src="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes23.png" alt="" width="419" height="430" /></a></p>
<p>This type graph is fully simplified (it&#8217;s a bit of a monster though!).  This is because simplification does not attempt to eliminate <em>equivalent</em> nodes from a union, only <em>identical</em> ones.  After minimisation, the outermost union will be removed and we&#8217;ll be left with just this:</p>
<p style="text-align: center;"><a href="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes24.png"><img class="aligncenter size-full wp-image-3078" style="border: 0pt none;" title="SimplifyingRecursiveTypes24" src="http://whiley.org/wp-content/uploads/2011/08/SimplifyingRecursiveTypes24.png" alt="" width="138" height="176" /></a></p>
<p>Now, back to the original issue.  In the general case, we can remove a union node from between any two nodes.  However, we cannot remove other kinds of nodes unless the entire subtree below that node is removed.  Therefore, we cannot introduce a union of union through this process.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/08/30/simplification-vs-minimisation-of-types-in-whiley/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Subtyping Gotcha</title>
		<link>http://whiley.org/2011/08/29/a-subtyping-gotcha/</link>
		<comments>http://whiley.org/2011/08/29/a-subtyping-gotcha/#comments</comments>
		<pubDate>Mon, 29 Aug 2011 03:37:05 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Structural Subtyping]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Typing]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=3040</guid>
		<description><![CDATA[<p>An interesting issue with the following piece of code has recently come to my attention:</p> define Queue as process { [int] items } int Queue::get(): item = this.items[0] this.items = this.items[1..] return item void Queue::put(int item): this.items = this.items + [item] Queue ::Queue(): // following line should be invalid return spawn { items: [] <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/08/29/a-subtyping-gotcha/">A Subtyping Gotcha</a></span>]]></description>
			<content:encoded><![CDATA[<p>An interesting issue with the following piece of code has recently come to my attention:</p>
<pre class="brush: whiley;">
define Queue as process { [int] items }

int Queue::get():
    item = this.items[0]
    this.items = this.items[1..]
    return item

void Queue::put(int item):
    this.items = this.items + [item]

Queue ::Queue():
    // following line should be invalid
    return spawn { items: [] }
</pre>
<p>The problem is that this code <em>should not compile</em>.  More specifically, the constructor <code>::Queue</code> should generate a syntax error.</p>
<p>The reason for this is that <em>we cannot safely subtype processes</em>.  To see why, consider the following (artificial) example:</p>
<pre class="brush: whiley;">
define MyProc as process { [int] field }
define BrokenProc as process { [int]|int field }

BrokenProc ident(MyProc mp):
    return mp // should not be allowed

void ::breakIt(MyProc mp):
    bp = ident(mp)
    bp.field = 1 // uh oh

[int] ::broken(MyProc mp):
    breakIt(mp)
    return mp.field // should be ok, but isn't...
</pre>
<p>The problem here arises from <em>aliasing</em>.  That is, since both <code>mp</code> and <code>bp</code> refer to the same process and, hence, assigning to <code>bp.field</code> corrupts the type of <code>mp.field</code>.  To resolve the above problem we require that <code>MyProc</code> is not a subtype of <code>BrokenProc</code>.  In other words, <em>no subtyping between process types should allowed</em>. </p>
<p>This issue may seem fairly innocuous since we easily can &#8220;fix&#8221; it by preventing subtyping between processes.  Unfortunately, does this means <code>spawn {field: []}</code> is not a subtype of <code>MyProc</code> either, since it has type <code>process {[void] field}</code>.  In other words, we cannot initialise a process field with an empty list!  There are some well-known ways in which we might get around this.  In particular, if we have a <em>unique reference</em> to a process, then subtyping is safe.  Looking at the <code>::Queue</code> constructor again, we actually do have a unique reference since we just spawned it!</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/08/29/a-subtyping-gotcha/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Whiley v0.3.9 Released!</title>
		<link>http://whiley.org/2011/08/15/whiley-v0-3-9-released/</link>
		<comments>http://whiley.org/2011/08/15/whiley-v0-3-9-released/#comments</comments>
		<pubDate>Mon, 15 Aug 2011 08:38:13 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Performance]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Wyclipse]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2994</guid>
		<description><![CDATA[<p>So, it&#8217;s that time again for another update of the Whiley compiler. Perhaps the most interesting update is that constraints are back! Admitedly, only runtime checking of constraints is back; and, there are quite a few problems with it. But, it&#8217;s a step in the right direction, and I&#8217;m pretty excited about it.</p> <p>I&#8217;ve <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/08/15/whiley-v0-3-9-released/">Whiley v0.3.9 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>So, it&#8217;s that time again for another update of the Whiley compiler.  Perhaps the most interesting update is that <em>constraints are back</em>!  Admitedly, only runtime checking of constraints is back; and, there are quite a few problems with it.  But, it&#8217;s a step in the right direction, and I&#8217;m pretty excited about it.</p>
<p>I&#8217;ve also been doing some more work on the benchmark suite.  In particular, the Java Bytecode disassembler is coming along.  One problem I&#8217;ve encountered, unfortunately, is that my type system implementation remains quite fragile.  I will need to harden this up before the next release, otherwise I&#8217;ll never get the disassembler working &#8230;</p>
<h2>Performance</h2>
<p>Aside from large benchmarks (e.g. Chess and the Disassembler), I&#8217;ve also been adding micro benchmarks (both sequential and concurrent).  For the sequential ones, I&#8217;ve provided a Java implemetation as well for comparison purposes.  I thought it would be interesting to see how Whiley compares, so here we go:</p>
<p><a href="http://whiley.org/wp-content/uploads/2011/08/raw.jpg"><img class="aligncenter size-full wp-image-2997" style="border: 0pt none;" title="raw" src="http://whiley.org/wp-content/uploads/2011/08/raw.jpg" alt="" width="538" height="403" /></a>Note the log scale.  As expected, performance is truly woeful.  However, it provides a useful start point for  improving performance &#8230;</p>
<h2>Wyclipse</h2>
<p>Another interesting development, is that I&#8217;ve begun the process of  constructing an Eclipse plugin.  Things are pretty rudimentary at the  moment, but I was able to get an editor with syntax highlighting working  quite easily!  You can see the code over on <a href="https://github.com/DavePearce/wyclipse">GitHub</a>.</p>
<h2>ChangeLog</h2>
<ul>
<li>Added support for &#8220;headless&#8221; methods.  A headless method is a method which has side-effects but has no explicit receiver.  Such methods are useful, for example, for implementing constructors.</li>
<li>Added ability to iterate strings and dictionaries.</li>
<li>Changed semantics for dictionaries to support updating of keys.</li>
<li>Put back in support for runtime constraint checking.  The main outstanding issue here is that loop invariants don&#8217;t work.</li>
<li>Turned off constant propagation because it&#8217;s causing lots of problems in relation to the constraints.</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.9.tgz" title="Download wdk-src-v0.3.9">wdk-src-v0.3.9</a><br />
      Created on February 7, 2012.  83 Downloads, 1.8 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.9.jar" title="Download wyjc-v0.3.9">wyjc-v0.3.9</a><br />
      Created on February 7, 2012.  110 Downloads, 745.7 KB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/08/15/whiley-v0-3-9-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Parallel Sum in Whiley</title>
		<link>http://whiley.org/2011/08/03/parallel-sum-in-whiley/</link>
		<comments>http://whiley.org/2011/08/03/parallel-sum-in-whiley/#comments</comments>
		<pubDate>Tue, 02 Aug 2011 21:49:48 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Examples]]></category>
		<category><![CDATA[Actors]]></category>
		<category><![CDATA[Concurrency]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2973</guid>
		<description><![CDATA[<p>Recently, I&#8217;ve been working on a variety of sequential and concurrent micro benchmarks for testing Whiley&#8217;s performance.  An interesting and relatively simple example, is the parallel sum.  The idea is to sum a large list of integers whilst performing as much work as possible in parallel.</p> <p>To implement the parallel sum, I divide the <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/08/03/parallel-sum-in-whiley/">Parallel Sum in Whiley</a></span>]]></description>
			<content:encoded><![CDATA[<p>Recently, I&#8217;ve been working on a variety of sequential and concurrent micro benchmarks for testing Whiley&#8217;s performance.  An interesting and relatively simple example, is the parallel sum.  The idea is to sum a large list of integers whilst performing as much work as possible in parallel.</p>
<p>To implement the parallel sum, I divide the list into roughly equal sized chunks and assign one process to each:</p>
<pre class="brush: whiley;">
define Sum as process {
    [int] items,
    int start,
    int end,
    int result
}

void Sum::start():
    sum = 0
    for i in start..end:
        sum = sum + items[i]
    this.result = sum

int Sum::get():
    return result

// Sum constructor
Sum ::Sum([int] is, int s, int e):
    return spawn {
        items: i,
        start: s,
        end: e,
        result: 0
    }
</pre>
<p>Essentially, each <code>Sum</code> process holds the original list of <code>items</code> and a range <code>start..end</code> over which to operate.  The <code>result</code> is used to store the final sum until it is requested by the outer loop.  The idea is that we first construct the processes, then start them all asynchronously and, finally, collect up the results.</p>
<p>The outer loop looks something like this:</p>
<pre class="brush: whiley;">
define N as 100 // block size to use

int ::parSum([int] items):
    while |items| != 1:
        // Calculate how many workers required
        nworkers = max(1,|items| / N)
        size = |items| / nworkers
        // Construct and start workers
        pos = 0
        workers = []
        for i in 0..nworkers:
            if i &lt; (nworkers-1):
                worker = Sum(items,pos,pos+size)
            else:
                // Last worker picks up the slack
                worker = Sum(items,pos,|items|)
            // Start worker asynchronously
            worker!start()
            // Bookkeeping
            workers = workers + [worker]
            pos = pos + size
     // Collect up results
     items = []
     for i in 0 .. nworkers:
         items = items + [workers[i].get()]
 return items[0]
</pre>
<p>The key here is that the outer loop continues until the original list of <code>items</code> is reduced to a single result.  There maybe several iterations required, depending on the block size.  Furthermore, the block size determines how many items will be processed by each process in one go.  Smaller block sizes lead to more parallelism, but have higher overheads.  The optimal block size probably depends on the underlying architecture, and would ideally be chosen at runtime.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/08/03/parallel-sum-in-whiley/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whiley v0.3.8 Released!</title>
		<link>http://whiley.org/2011/08/01/whiley-v0-3-8-released/</link>
		<comments>http://whiley.org/2011/08/01/whiley-v0-3-8-released/#comments</comments>
		<pubDate>Sun, 31 Jul 2011 21:59:10 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2959</guid>
		<description><![CDATA[<p>Now that teaching has started up again, development has slowed a little. This release is primarily a bug fix release. The benchmarks and examples now all compile again, which is great! I&#8217;ve also significantly increased the number of micro benchmarks, as I&#8217;m gear up for some performance testing &#8230;</p> ChangeLog <p>The main changes since <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/08/01/whiley-v0-3-8-released/">Whiley v0.3.8 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>Now that teaching has started up again, development has slowed a little.  This release is primarily a bug fix release.  The benchmarks and examples now all compile again, which is great!  I&#8217;ve also significantly increased the number of micro benchmarks, as I&#8217;m gear up for some performance testing &#8230;</p>
<h2>ChangeLog</h2>
<p>The main changes since v0.3.7 are:</p>
<ul>
<li>Added proper support for internal message sends.</li>
<li>Reworked the JVM implementation behind coercions.</li>
<li>Added support for detecting ambiguous coercions, and reporting a syntax error.</li>
<li>Added support for an explicit cast operator, which follows C&#8217;s cast syntax.</li>
<li>Fixed numerous bugs</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.8.tgz" title="Download wdk-src-v0.3.8">wdk-src-v0.3.8</a><br />
      Created on January 1, 1970.  78 Downloads, 1.7 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.8.jar" title="Download wyjc-v0.3.8">wyjc-v0.3.8</a><br />
      Created on January 1, 1970.  93 Downloads, 714.2 KB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/bench/wybench-v0.1.4.tgz" title="Download wybench-v0.1.4">wybench-v0.1.4</a><br />
      Created on July 31, 2011.  82 Downloads, 3.5 MB.<br/>
      Freeware
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/08/01/whiley-v0-3-8-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Semantic Interpretation of Types in Whiley</title>
		<link>http://whiley.org/2011/07/29/semantic-interpretation-types-whiley/</link>
		<comments>http://whiley.org/2011/07/29/semantic-interpretation-types-whiley/#comments</comments>
		<pubDate>Thu, 28 Jul 2011 23:11:04 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Interest]]></category>
		<category><![CDATA[Theory]]></category>
		<category><![CDATA[Types]]></category>
		<category><![CDATA[Typing]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2659</guid>
		<description><![CDATA[<p>An interesting and intuitive way of thinking about a type system is using a semantic interpretation.  Typically, a set-theoretic model is used where a type T is a subtype of S iff every element in the set described by T is in the set described by S.</p> The Semantic Model <p>The starting point is <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/07/29/semantic-interpretation-types-whiley/">A Semantic Interpretation of Types in Whiley</a></span>]]></description>
			<content:encoded><![CDATA[<p>An interesting and intuitive way of thinking about a type system is using a <em>semantic interpretation</em>.  Typically, a set-theoretic model is used where a type <code>T</code> is a subtype of <code>S</code> iff every element in the set described by <code>T</code> is in the set described by <code>S</code>.</p>
<h2>The Semantic Model</h2>
<p>The starting point is to define our notion of types <code>T</code> and values <code>V</code>:</p>
<ul>
<li><code>T ::= null | int | any | [T] | {T1 f1, ... Tn fn} | T1 ∨ T2</code></li>
</ul>
<ul>
<li><code>V ::= null | i | [V1,...,Vn] | {f1: V1, ... f2: V2}</code></li>
</ul>
<p>This is a simplified notion of the types and values found in Whiley.  For example, I&#8217;ve left out sets and function references and ignored recursive types altogether.</p>
<p>We can define our semantic model as follows using an acceptance relation <code>T</code> |= <code>V</code>, which holds if value <code>V</code> is in the set described by type <code>T</code>.</p>
<ul>
<li><code>null</code> |= <code>null</code></li>
<li><code>any</code> |= <code>V</code></li>
<li><code>int</code> |= <code>i</code>, <strong>if</strong> i ∈ <em>I</em> (the set of all integers)</li>
<li><code>[T]</code> |= <code>[V1,...Vn]</code>, <strong>if</strong> ∀1≤i≤n.[<code>T</code> |= <code>Vi</code>]</li>
<li><code>{T1 f1, ..., Tn fn}</code> |= <code>{f1: V1, ... fn: Vn}</code>, <strong>if</strong> <code>T1</code> |= <code>V1</code>, &#8230; <code>Tn</code> |= <code>Vn</code></li>
<li><code>T1 ∨ T2 </code> |= <code>V</code>, <strong>if</strong> <code>T1</code> |= <code>V</code> <strong>or</strong> <code>T2</code> |= <code>V</code></li>
</ul>
<p><strong>Note:</strong> this model could be made more advanced by supporting <a href="http://en.wikipedia.org/wiki/Subtype_polymorphism#Record_types">width subtyping</a> &#8212; but its enough for now.</p>
<p>Finally, we can give a semantic notion of subtyping where <code>T1</code> |= <code>T2</code> holds if ∀<code>V</code>.[<code>T1</code> |= <code>V</code> <strong>implies</strong> <code>T2</code> |= <code>V</code>].  In otherwords, <code>T1</code> |= <code>T2</code> if <code>T1</code> is a subtype of <code>T2</code>.</p>
<h2>The Subtyping Algorithm</h2>
<p>Now that we have an &#8220;intuitive&#8221; model of what types should mean, we want to compare that against an actual algorithm for subtype testing.  The following pseudo-code outlines the basic algorithm used in Whiley:</p>
<pre class="brush: whiley;">
// Check whether t1 is a subtype of t2
bool isSubtype(Type t1, Type t2):
   // rule 1
   if t2 is any:
       return true
   // rule 2
   else if t1 == t2:
       return true
   // rule 3
   else if t1 is [t3] &amp;&amp; t2 is [t4]:
       return isSubtype(t3,t4)
   // rule 4
   else if t1 is {t3 f3, ..., Tn fn} &amp;&amp;
            t2 is {s3 f3, ..., Sn fn}:
       for i in 3..n:
           if !isSubtype(ti,si):
               return false
       return true
   // rule 5
   else if t1 is (t3 ∨ t4):
       return isSubtype(t3,t2) &amp;&amp; isSubtype(t4,t2)
   // rule 6
   else if t2 is (t3 ∨ t4):
       return isSubtype(t1,t3) || isSubtype(t1,t4)
   // rule 7
   else:
       return false
</pre>
<p>Thus, for example, <code>isSubtype(int,any)</code> holds under rule 1, whilst <code>isSubtype(int,int ∨ null)</code> holds by rules 6+2.</p>
<h2>The Question</h2>
<p><center><em>Is the subtyping algorithm sound and complete with respect to our semantic model?</em></center><br />
In some sense, the whole point of the semantic model is to let us ask this question.  We can break this down into two separate questions of <em>soundness</em> and <em>completeness</em>:</p>
<blockquote><p><strong>Soundness.</strong> If <code>isSubtype(T1,T2)</code> then <code>T1</code> |= <code>T2</code>.</p></blockquote>
<blockquote><p><strong>Completeness.</strong> If <code>T1</code> |= <code>T2</code> then <code>isSubtype(T1,T2)</code>.</p></blockquote>
<p>Considering these questions separately simplifies the problem.  I&#8217;m not going to provide any proofs, but it&#8217;s relatively easy to see that <code>isSubtype()</code> is sound.  The more interesting question is whether or not it is complete.</p>
<p>In fact, it turns out that the <code>isSubtype()</code> algorithm as given is <em>not complete</em>.  A simple counter-example is sufficient to show this.  Let <code>T1</code> = <code>{int ∨ null x}</code> and <code>T2</code> = <code>{int x} ∨ {null x}</code> .  Then, <code>T1</code> |= <code>T2</code>, but <code>isSubtype(T1,T2)</code> does not hold.  This is because rule 6 requires <code>isSubtype(T1,{int x})</code> and <code>isSubtype(T1,{null x})</code> (neither of which hold).</p>
<p>The problem is that <code>isSubtype()</code> is not <em>distributive</em> over records.  An interesting question is how we can fix it, but that&#8217;s a story for another day!</p>
<p>If you&#8217;re interested in learning more about this, I&#8217;ve worked through the full system in <a href="http://homepages.ecs.vuw.ac.nz/~djp/files/ECSTR10-23.pdf">this paper</a>.  Also, the following reference provides a good introduction to semantic subtyping:</p>
<ul>
<li>&#8220;<strong>A Gentle Introduction to Semantic Subtyping&#8221;</strong>, Giuseppe Castagna and Alain Frisch.  In Proceedings of the ACM Conference on Principles and practice of declarative programming (PPDP), 2005. [<a href="http://portal.acm.org/citation.cfm?id=1069793">ACM Link</a>][<a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.65.8026&#038;rep=rep1&#038;type=pdf">PDF</a>]</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/07/29/semantic-interpretation-types-whiley/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>The State of Whiley</title>
		<link>http://whiley.org/2011/07/26/the-state-of-whiley/</link>
		<comments>http://whiley.org/2011/07/26/the-state-of-whiley/#comments</comments>
		<pubDate>Tue, 26 Jul 2011 00:25:12 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Implementation]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Typing]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2814</guid>
		<description><![CDATA[<p>The aim of this post is simply to list the main outstanding issues with the design and implementation of Whiley.  This is primarily for my own purposes, in order to help me focus my efforts and to ensure I don&#8217;t forget something important.</p> Syntax <p>Deciding upon the language syntax is obviously the highest priority <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/07/26/the-state-of-whiley/">The State of Whiley</a></span>]]></description>
			<content:encoded><![CDATA[<p>The aim of this post is simply to list the main outstanding issues with the design and implementation of Whiley.  This is primarily for my own purposes, in order to help me focus my efforts and to ensure I don&#8217;t forget something important.</p>
<h2>Syntax</h2>
<p>Deciding upon the language syntax is obviously the highest priority for me right now.  Over the last six months, a lot of the syntax has been locked down.  However, there remains a number of issues (some of which are thorny).</p>
<ul>
<li><strong>Message Send Syntax</strong>. Currently, the syntax for sending messages to actors is not finalised.  <a href="http://whiley.org/2011/06/28/disambiguating-ambiguous-syntax/">This post</a> provides all of the interesting details.</li>
<li><strong>Implicit Coercions</strong>. These are causing me something of a headache as, in the context of structural subtyping, they&#8217;re quite tricky.  <a href="http://whiley.org/2011/07/21/implicit-coercions-in-whiley/">This post</a> provides some insight into the problem, as does <a href="http://whiley.org/2011/07/07/whiley-v0-3-7-released/">this post</a>.</li>
<li><strong>Default Imports.</strong> Currently, like Java, every Whiley source file implicitly imports <code>whiley.lang.*</code> which (I think) is a bad idea.  The reason for this is that it doesn&#8217;t make sense to unnecessarily clutter the namespace of every source file.  On the other hand, it is annoying to have to include that import explicitly, as most files will probably want it.</li>
<li><strong>Imports</strong>.  Currently, when you import a module, all names from that module are imported directly.  For example, suppose a module <code>String</code> contains a function <code>indexOf()</code>.  The statement <code>import String</code> will import the name <code>indexOf</code> directly into our namespace.  This is convenient, but opens up potential for name clashes.  It might be better for <code>import String</code> to import the name <code>String.indexOf</code> rather than just <code>indexOf</code> (like Python).</li>
<li><strong>Encapsulation</strong>.  Currently, there is no real support for encapsulation modifiers (e.g. <code>public</code>, <code>private</code>, etc). I plan to support <code>public</code> and <code>private</code> in the obvious ways.  However, I also want a third option.  Consider the definition <code>public define Rec as {int x}</code>.  This makes the name <em>and its contents</em> visible to clients.  But, I also want to be able to export the name <em>without its contents</em>.  The two options I&#8217;m considering are: using <code>protected</code> for this to be used in place of <code>public</code>; or, providing a special <code>export</code> declaration.  The idea of the latter is that, for a <code>private</code> type, we can declare something like <code>export Rec</code> &#8212; this just makes the name <code>Rec</code> visible to clients, and nothing else.  I&#8217;m leaning towards <code>protected</code> as it&#8217;s simpler, but it would cause some confusion with the meaning of <code>protected</code> in other languages.</li>
<li><strong>Interface Syntax.</strong> Currently, there is no way to declare an <code>interface</code>, such as e.g. <code>Reader</code> in Java.  This is a serious deficiency which I will rectify as soon as I figure out the best way of doing it.</li>
<li><strong>Bindings.</strong> Currently, every function or method compiled to JVM Bytecode has its name mangled &#8230; which makes it impossible to call such functions/methods from native Java.  I am considering providing a &#8220;binding&#8221; modifier for methods/functions.  This would ensure a version of the method/function existed which was unmangled.</li>
<li><strong>Entry Point.</strong> Currently, the entry point for a Whiley program is <code>void System::main([string] args)</code>.  This is problematic as it means that, until the main method exits, no actor can send a message to the <code>System</code> process.  One option is to support &#8220;headless&#8221; methods in Whiley &#8212; then, the signature would become e.g. <code>void ::main(</code><code>System sys, </code><code>[string] args)</code>.  In fact, the command-line arguments could be held in <code>sys</code> to further simplify this.</li>
<li><strong>Currying</strong>. Currently, you can take the address of a function (e.g. <code>&amp;f</code>).  However, you cannot curry functions.  So, I&#8217;d like to support syntax such as e.g. <code>&amp;f(2,_)</code>, where the underscore indicates the actual parameter.</li>
<li><strong>Actor Fields.</strong> Currently, you do not need to provide <code>this</code> when reading a field from <code>this</code> actor (unless a local variable of the same name already exists).  However, when assigning fields you do need to provide <code>this</code> (<a href="http://whiley.org/2010/10/05/field-resolutio-in-whiley/">this post</a> discusses why)  Likewise, you currently need to provide <code>this</code> when making an internal message send (however, I could infer it in most cases).  I&#8217;m wondering whether or not requiring <code>this</code> in all cases would be more a uniform approach, and give better readability.</li>
<li><strong>String Conversions</strong>.  Currently, the system does not implicitly convert data types into strings.  Instead, you must explicitly call <code>str()</code>.  For example, to print an integer <code>i</code>, you would write <code>out.println(str(i))</code>.  This seems a little cumbersome, and somewhat unnecessary.</li>
</ul>
<h2>Implementation</h2>
<p>The current implementation targets the Java Virtual Machine and, for the most part, is in good shape.  However, there are a number of outstanding issues.</p>
<ul>
<li><strong>Type System</strong>.  My work on formalising Whiley&#8217;s type system has thrown up a number of interesting issues.  In particular: types are not currently represented in a canonical fashion; they do not support distributivity across records/function types; and, ideally, they would include intersection and negation as first-class components.</li>
<li><strong>Dictionary and String Iteration</strong>.  You cannot at the moment iterate over dictionaries or strings using the for loop.  This is a minor issue to fix.</li>
<li><strong>Break/Continue Statements</strong>.  Break and continue statements are only semi-working right now.  Again, only a minor issue.</li>
<li><strong>Exceptions</strong>.  At the moment you can <code>throw</code> exceptions, but you cannot <code>catch</code> them!  This should be easy to fix.  I need to consider whether or not a <code>finally</code> block is required.</li>
<li><strong>Actors</strong>.  At the moment, Actors are currently implemented using a single <code>Thread</code> per actor.  This is highly inefficient, and eventually we will support <em>green threads</em>.</li>
<li><strong>Native function/method declarations</strong>.  I will provide a <code>native</code> modifier for functions/methods to indicate they are provided by the system.</li>
<li><strong>Whiley Bytecode File Format</strong>.  There is no binary file format for wyil files.  Thus, all signature information is currently stored directly in the Java classfile.  Eventually, however, such information will be stored in a binary wyil file (similar, in some ways, to a header file in C).  Then, the WHILEYPATH will only be searched for wyil files, not Java classfiles.  The primary reason for this is to support compilation to non-JVM targets, such as machine code.<strong></strong></li>
<li><strong>Record Access Bytecode</strong>s. Currently a record access requires a specific type (i.e. <code>Type.Record</code>) which is generated from <code>effectiveRecordType()</code>.  This is  a problem as the back-end loses knowledge of the actual representation of types.  For example, <code>{int x}|{[int] x}</code> is converted by <code>effectiveRecordType()</code> into <code>{int|[int] x}</code> to be stored in a <code>FieldAccess</code> bytecode.  This presents a problem if {int x} is represented differently from <code>{int|[int] x}</code> (which it might be in the case of <code>int</code> being implemented using a native <code>int</code>).</li>
</ul>
<p>And, of course, there are quite a few outstanding bugs yet to be fixed!</p>
<h2>Performance</h2>
<p>Performance is a significant issue in Whiley at the moment.  It&#8217;s unlikely that this will change in the near future, however eventually I will address it.  There are currently three main techniques that I will use to address this:</p>
<ul>
<li><strong>Reference Counting</strong>.  Here, the idea is that every compound structure (e.g. a list) maintains a reference count.  Then, when an update is made to a compound structure, the count is checked.  If its <code>&gt; 1</code> the structure is cloned; otherwise, the update occurs in place.  See <a href="http://www.sable.mcgill.ca/mclab/mcvm/mcvmcc2011.pdf">this paper</a> for more on how this might work.</li>
<li><strong>Integer Range Analysis</strong>.  A significant challenge in Whiley (from a performance perspective) is that the <code>int</code> type represents <em>unbounded integers</em> which are currently implemented as a <code>BigInteger</code>.  However, when possible, we want to use native JVM ints.  In order to do this, I propose using an integer range analysis to determine the lower and upper bounds of a given type.  This would be performed intra-procedurally and, in conjunction with pre/post-conditions, it should be very effective.  See <a href="http://user.it.uu.se/~svenolof/IRA01/">this link</a> for relevant papers.</li>
<li><strong>Native Lists/Sets</strong>.  Currently, lists of e.g. bytes are implemented as e.g. <code>ArrayList&lt;Byte&gt;</code>.  This is not efficient and I want to provide specific list implementations which (in this case) would use <code>byte[]</code> internally.</li>
<li><strong>Representation of Records.</strong> Currently records are represented by <code>HashMap</code>.  However, it would be more efficient to represent them as <code>Object[]</code>, giving guaranteed constant-time lookup.</li>
<li><strong>Tagged Unions</strong>.  In some cases, a tagged union could speed up runtime type tests.</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/07/26/the-state-of-whiley/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implicit Coercions in Whiley</title>
		<link>http://whiley.org/2011/07/21/implicit-coercions-in-whiley/</link>
		<comments>http://whiley.org/2011/07/21/implicit-coercions-in-whiley/#comments</comments>
		<pubDate>Thu, 21 Jul 2011 07:06:29 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Typing]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2797</guid>
		<description><![CDATA[<p>The issue of implicit coercions in Whiley is proving to be a particularly thorny issue.  The following motivates why (I think) coercions make sense:</p> real f(int x, real y): return x + y real g(int x, int y): return f(x,y) <p>I believe the above should compile without error.  However, this requires an implicit coercion <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/07/21/implicit-coercions-in-whiley/">Implicit Coercions in Whiley</a></span>]]></description>
			<content:encoded><![CDATA[<p>The issue of <a href="http://en.wikipedia.org/wiki/Type conversion" target="_top" >implicit coercions</a> in Whiley is proving to be a particularly thorny issue.  The following motivates why (I think) coercions make sense:</p>
<pre class="brush: whiley;">
real f(int x, real y):
    return x + y

real g(int x, int y):
    return f(x,y)
</pre>
<p>I believe the above should compile without error.  However, this requires an implicit coercion from <code>int</code> to <code>real</code> in several places.  Some statically typed programming languages (notably <a href="http://en.wikipedia.org/wiki/ML (programming language)" target="_top" >ML</a>) simply don&#8217;t perform <em>any</em> implicit coercions.  Instead, they require explicit coercions in the form of type casts.  Under this model, the above code would be:</p>
<pre class="brush: whiley;">
real f(int x, real y):
    return real(x) + y

real g(int x, int y):
    return f(x,real(y))
</pre>
<p>To me, this seems rather cumbersom and, <em>when it&#8217;s clear from the context</em>, I want the compiler to do this for me.</p>
<p>So, what coercions could we support in Whiley?  Here&#8217;s a taster:</p>
<ul>
<li><code>int</code> &#8211;&gt; <code>real</code></li>
<li><code>{int x, int y}</code> &#8211;&gt; <code>{int y}</code></li>
<li><code>[int]</code> &#8211;&gt; <code>{int}</code></li>
<li><code>{int-&gt;int}</code> &#8211;&gt; <code>{int,int}</code></li>
<li><code>[string]</code> &#8211;&gt; <code>{int-&gt;string}</code></li>
</ul>
<p>Unfortunately, whilst this looks all good on the surface, there are some tricky cases.  Here&#8217;s one example:</p>
<pre class="brush: whiley;">
define Rec1 as { int x, real y }
define Rec2 as { real x, int y }
define Rec12 as Rec1 | Rec2

int f(Rec12 r):
   if r is Rec1:
       return r.x
   else:
       return r.y

int test():
   z = {x: 1, y: 1} // z has type {int x, int y}
   return f(z)
</pre>
<p>The problem here is that we cannot determine whether to coerce <code>z</code> to <code>Rec1</code> or <code>Rec2</code>.  I guess we should report an ambiguous coercion error.  Which immediately raises the question of how, in the general case, I detect this.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/07/21/implicit-coercions-in-whiley/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Compile-time Verification, It&#8217;s Not Just for Type Safety Any More</title>
		<link>http://whiley.org/2011/07/12/compile-time-verification-its-not-just-for-type-safety-any-more/</link>
		<comments>http://whiley.org/2011/07/12/compile-time-verification-its-not-just-for-type-safety-any-more/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 21:00:57 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Interest]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2794</guid>
		<description><![CDATA[<p>I just came across an interesting presentation over at InfoQ called &#8220;Compile-time Verification, It&#8217;s Not Just for Type Safety Any More&#8220;:</p> <p>The talk is by Greg Young and focuses on .Net&#8217;s contracts library.  It&#8217;s quite interesting, and you can see the contracts in action.  From my perspective, what&#8217;s very interesting is that he shows <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/07/12/compile-time-verification-its-not-just-for-type-safety-any-more/">Compile-time Verification, It&#8217;s Not Just for Type Safety Any More</a></span>]]></description>
			<content:encoded><![CDATA[<p>I just came across an interesting presentation over at InfoQ called &#8220;<a href="http://www.infoq.com/presentations/Contracts-Library;jsessionid=92B2D3EAF4BE1532C443704EEE19E7E9">Compile-time Verification, It&#8217;s Not Just for Type Safety Any More</a>&#8220;:</p>
<p>The talk is by Greg Young and focuses on .Net&#8217;s contracts library.  It&#8217;s quite interesting, and you can see the contracts in action.  From my perspective, what&#8217;s very interesting is that he shows <em>compile-time checking</em> of contracts &#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/07/12/compile-time-verification-its-not-just-for-type-safety-any-more/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Whiley v0.3.7 Released!</title>
		<link>http://whiley.org/2011/07/07/whiley-v0-3-7-released/</link>
		<comments>http://whiley.org/2011/07/07/whiley-v0-3-7-released/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 22:44:34 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2774</guid>
		<description><![CDATA[<p>Development has continued at a fairly quick pace since the last release of Whiley.  However, with the impending start of term, things are bound to slow down.  Therefore, I&#8217;m making a release now a little sooner that otherwise planned.  This fixes a number of important bugs, finally allowing the compiler to compile my benchmark <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/07/07/whiley-v0-3-7-released/">Whiley v0.3.7 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>Development has continued at a fairly quick pace since the last release of Whiley.  However, with the impending start of term, things are bound to slow down.  Therefore, I&#8217;m making a release now a little sooner that otherwise planned.  This fixes a number of important bugs, finally allowing the compiler to compile my benchmark suite again.</p>
<h2>Issues</h2>
<ul>
<li>The syntax for synchronous and asynchronous message sends is still causing headaches.  I&#8217;ve summarised the main problems <a href="http://whiley.org/2011/06/28/disambiguating-ambiguous-syntax/">in this post</a>.</li>
<li>I&#8217;m also a little concerned about my rules for implicit coercions.  For example, for a set union operation with type <code>{real}+[int]</code>, the right-hand side is implicitly coerced to be <code>{int}</code> and, hence, the result type is <code>{real|int}</code>.  In contrast, things behave slightly differently for an intersection with type <code>{real}&amp;[int]</code>.  In this case, the right-hand side is coerced into <code>{real}</code>, not <code>{int}</code>.  The reason for this is that, otherwise, the operation doesn&#8217;t make sense &#8212; as <code>{real}&amp;{int}</code> would always return the empty set.  These rules seem a little confusing to me, and I suspect I need a clearer (perhaps less powerful) model.</li>
<li>I&#8217;m a little uneasy over the list append and set union regarding element additions.  For example, in an append of type <code>[int]+int</code>, the right-hand side is added as an element type of <code>[int]</code>.  I&#8217;m just not sure if I like this or not.</li>
</ul>
<h2>ChangeLog</h2>
<ul>
<li>Added first-class <code>char</code> and <code>byte</code> types, which compile down to their primitive equivalents on the JVM.  A <code>byte</code> is somewhat different from that in Java, however, as it is <em>not interpreted</em>.  That is, it corresponds simply to a sequence of 8 bits.  You can perform the usual array of bitwise operations (<code>&amp;</code>, <code>|</code>, <code>^</code>, <code>&lt;&lt;</code> and <code>&gt;&gt;</code>).  However, unlike Java, a <code>byte</code> will not implicitly coerce into an <code>int</code>. Instead, you have to use a method which constructs an <code>int</code> assuming some kind of bit representation.  Probably the most common one will be <code>le2uint(byte)</code>, which generates and unsigned integer from a byte assuming a <a href="http://en.wikipedia.org/wiki/Endianness" target="_top" >little endian</a> layout.  More discussion of the <code>byte</code> type can be <a href="http://whiley.org/2011/07/04/bits-bytes-more-ambiguous-syntax/">found in this post</a>.</li>
<li>Added support for method pointers.  This allows references to methods to be passed around, just like for function pointers.  An example method pointer type would be <code>int(Reader)::(int)</code> &#8212; this indicates a pointer to a method whose receiver is a <code>Reader</code> and which accepts an <code>int</code> parameter and returns an <code>int</code> value.</li>
<li>Fixed a lot of bugs.</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.7.jar" title="Download wyjc-v0.3.7">wyjc-v0.3.7</a><br />
      Created on January 1, 1970.  68 Downloads, 702.6 KB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.7.tgz" title="Download wdk-src-v0.3.7">wdk-src-v0.3.7</a><br />
      Created on January 1, 1970.  40 Downloads, 1.7 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/bench/wybench-v0.1.3.tgz" title="Download wybench-v0.1.3">wybench-v0.1.3</a><br />
      Created on July 6, 2011.  82 Downloads, 2.2 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/07/07/whiley-v0-3-7-released/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Regular Tree Automata</title>
		<link>http://whiley.org/2011/07/06/regular-tree-automata/</link>
		<comments>http://whiley.org/2011/07/06/regular-tree-automata/#comments</comments>
		<pubDate>Wed, 06 Jul 2011 06:01:38 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Interest]]></category>
		<category><![CDATA[Structural Subtyping]]></category>
		<category><![CDATA[Tree Automata]]></category>
		<category><![CDATA[Typing]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2762</guid>
		<description><![CDATA[<p>In my quest to understand the theory of recursive types in more detail, the notion of regular tree languages and Tree Automata has cropped up.  These have been used, amongst other things, for describing XML schemas.  They are also useful for describing recursive types as well!</p> <p>A nice example of a regular tree language <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/07/06/regular-tree-automata/">Regular Tree Automata</a></span>]]></description>
			<content:encoded><![CDATA[<p>In my quest to understand the theory of recursive types in more detail, the notion of regular tree languages and <a href="http://en.wikipedia.org/wiki/Tree automaton" target="_top" >Tree Automata</a> has cropped up.  These have been used, amongst other things, for describing <a href="http://en.wikipedia.org/wiki/XML schema" target="_top" >XML schemas</a>.  They are also useful for describing recursive types as well!</p>
<p>A nice example of a regular tree language is one for minimising <em>boolean expressions</em>.  The  constructors of the language are <code>True</code>,  <code>False</code>, <code>Not/1</code>, <code>And/2</code> and <code>Or/2</code>.  The regular tree language looks thus:</p>
<pre>Expr -&gt; True
     | False
     | Not(Expr)
     | And(Expr,Expr)</pre>
<p>This should look pretty familiar to anyone who&#8217;s studied context-free and/or regular languages before.  A simple (deterministic) bottom-up tree automata can then be defined using the following state transitions:</p>
<pre>True --&gt; q1            Not(q0) --&gt; q1
False --&gt; q0           Not(q1) --&gt; q0
And(q0,q0) --&gt; q0      And(q1,q0) --&gt; q0
And(q0,q1) --&gt; q0      And(q1,q1) --&gt; q1</pre>
<p>I guess the interesting question is how this differs from general regular languages.  They appear to be very similar &#8212; for example, they support minimisation, intersection and union (amongst other things).  Likewise, the relationship with context-free grammar is interesting &#8230; although I haven&#8217;t got to the bottom of that yet.</p>
<p>Anyway, a good reference on this subject is the book <a href="http://tata.gforge.inria.fr/">Tree Automata Techniques and Applications</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/07/06/regular-tree-automata/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Bits, Bytes and More Ambiguous Syntax</title>
		<link>http://whiley.org/2011/07/04/bits-bytes-more-ambiguous-syntax/</link>
		<comments>http://whiley.org/2011/07/04/bits-bytes-more-ambiguous-syntax/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 05:15:52 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Syntax]]></category>
		<category><![CDATA[Types]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2747</guid>
		<description><![CDATA[<p>Recently, I added a first-class byte type to Whiley.  Unlike Java, this is not interpreted as some kind of signed or unsigned int. That&#8217;s because I find that very confusing since a byte is really just a sequence of bits without any interpretation. </p> <p>Therefore, in Whiley, a byte is just that: a bit <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/07/04/bits-bytes-more-ambiguous-syntax/">Bits, Bytes and More Ambiguous Syntax</a></span>]]></description>
			<content:encoded><![CDATA[<p>Recently, I added a first-class <code>byte</code> type to Whiley.  Unlike Java, this is not interpreted as some kind of signed or unsigned <code>int</code>.  That&#8217;s because I find that very confusing since a <code>byte</code> is really just a sequence of bits without any interpretation.  </p>
<p>Therefore, in Whiley, a <code>byte</code> is just that: a bit sequence on which you can perform the usual operations, such as bitwise AND/OR/XOR operations, as well as left and right shifts.  Here&#8217;s a snipper which accepts a <code>byte</code> and converts it into an unsigned <code>int</code> assuming a little endian representation:</p>
<pre class="brush: whiley;">
int le2uint(byte b):
    r = 0
    base = 1
    while b != 0b:
        if (b &amp; 00000001b) == 00000001b:
            r = r + base
        b = b &gt;&gt; 1
        base = base * 2
    return r
</pre>
<p>As usual, updating the compiler to support the <code>byte</code> type did not go according to plan.  That&#8217;s because I ran into yet another ambiguity of syntax.  This time the ambiguity is surrounding the <code>|</code> operator, which represents bitwise OR and is also a delineator for set comprehensions.  Consider these three examples:</p>
<pre class="brush: whiley;">
x = b1 | b2    // bitwise OR
y = { a | a in as,  a &gt; 0 }    // comprehension
z = { a | a in ys }    // hmmmm, set generator or comprehension?
</pre>
<p>In fact, it&#8217;s fairly easy to disambiguate the last statement &#8212; it must be a set comprehension.  That&#8217;s because <code>a in ys</code> has <code>bool</code> type, and this cannot be part of a bitwise OR operation.  However, at the point it needs to make this decision, the compiler doesn&#8217;t have access to type information.  This is because type propagation occurs after the source has been translated into the intermediate language (wyil).  But, there is no bytecode in the Wyil for a comprehension and, instead, it is constructed using <code>for</code> loops).</p>
<p>I believe it is possible to disambiguate bitwise OR from a set comprehension in the parser &#8212; however, for the moment, I just resolve it by preferring set comprehensions over bitwise OR.  The impact of this is that the expression <code>{ a|b }</code> won&#8217;t parse because it&#8217;s not a valid set comprehension (but is a valid set generator).  Instead, you have to help the parser using braces.  So, <code>{ a|b }</code> becomes <code>{ (a|b) }</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/07/04/bits-bytes-more-ambiguous-syntax/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Disambiguating Ambiguous Syntax?</title>
		<link>http://whiley.org/2011/06/28/disambiguating-ambiguous-syntax/</link>
		<comments>http://whiley.org/2011/06/28/disambiguating-ambiguous-syntax/#comments</comments>
		<pubDate>Tue, 28 Jun 2011 00:39:45 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Scoping]]></category>
		<category><![CDATA[Syntax]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2679</guid>
		<description><![CDATA[<p>When designing a programming language, being on the lookout for ambiguous syntax is important. You don&#8217;t want to realise down the track that your syntax is ambiguous in some subtle way. This is especially true if it means the compiler can&#8217;t decide how to proceed on some important case(s).  But, spotting these problems is <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/06/28/disambiguating-ambiguous-syntax/">Disambiguating Ambiguous Syntax?</a></span>]]></description>
			<content:encoded><![CDATA[<p>When designing a programming language, being on the lookout for ambiguous syntax is important.  You don&#8217;t want to realise down the track that your syntax is ambiguous in some subtle way. This is especially true if it means the compiler can&#8217;t decide how to proceed on some important case(s).  But, spotting these problems is not easy, especially when there are unexpected interactions between constructs.</p>
<h2>The Context</h2>
<p><strong> </strong> In the latest release of Whiley, I have relented to peer pressure and backed off from my earlier syntax for message sends.  To recall, this used <code>&lt;-&gt;</code> and <code>&lt;-</code> to signal synchronous and asynchronous message sends.  In particular, several people commented on how cumbersome <code>&lt;-&gt;</code> was.  Instead, the latest version of Whiley uses plain old <code>.</code> for synchronous sends, and <code>!</code> for asynchronous (i.e. like <a href="http://en.wikipedia.org/wiki/Erlang (programming language)" target="_top" >Erlang</a>).  Whilst in many ways this is rather nice, it does leave open an interesting question of <em>ambiguity</em>.</p>
<p>There are essentially two invocation forms the compiler encounters: <code>func()</code> and <code>x.meth()</code>.  The former is straightforward as it always corresponds to a function invocation.  The latter, however, is more subtle as it has two possible interpretations: a <em>direct message send</em>, or an <em>indirect function invocation</em> via a field dereference.</p>
<p>Here&#8217;s an example to illustrate a direct message send:</p>
<pre class="brush: whiley;">
define MyProc as { int data }

int MyProc::func():
    return this.data

int client(MyProc p):
    return p.func() // direct message send
</pre>
<p>And, here&#8217;s an example to illustrate an indirect function invocation via field dereference:</p>
<pre class="brush: whiley;">
define MyRec as { int() func }

int client(MyRec p):
    return p.func() // indirect function invocation
</pre>
<p>The question is: <em>how does the compiler disambiguate this?</em> Well,the (current) rule is simple:</p>
<blockquote><p>If a matching external symbol exists then its a direct message send; otherwise, it&#8217;s an indirect function invocation via field dereference.</p></blockquote>
<p>In otherwords, priority is given to <em>direct message sends</em>.  At this point, alarm bells should be starting to go off.  <em>Why?</em> Well, because external symbols may come and go &#8212; we have no control over them, and we don&#8217;t want changes in external libraries to affect the <em>semantics</em> of our code.  Considering the last example, suppose we ended up accidentally importing a matching external symbol:</p>
<pre class="brush: whiley;">
// following symbol from some imported module
int MyProc::func():
    ...

define MyRec as { int() func }

int client(MyRec p):
    return p.func() // indirect function invocation
</pre>
<p>Well, this code no longer compiles because <code>func</code> is resolved as an external symbol and, hence, the compiler is expecting <code>p</code> to have type <code>MyProc</code>.</p>
<h2>The Problem</h2>
<p>Now, it seems like the above problem just stems from a bad choice of rule.  Perhaps an alternative ruling would be better?  Well, we could give priority to field-dereferences.  This way, external symbols can&#8217;t affect field-dereferences.  But, now, field dereferences can affect external symbols!   To see why, consider this:</p>
<pre class="brush: whiley;">
define MyProc as {
 int data,
 int func()
}

int MyProc::func():
    return this.data

int client(MyProc p):
    return p.func() // what is it???
</pre>
<p>The problem here is that <em>either interpretation makes sense</em>.  We&#8217;re either indirectly invoking a function pointer stored in field <code>func</code> of process <code>p</code>, or making a direct message send to <code>p</code>.  Of course, we can choose how to resolve this (i.e. either field dereference or direct message send gets priority).</p>
<p>The problem is, whichever choice we make, it remains the case that <em>a change in an imported module can affect the semantics of our code</em>. To see why, assume <code>MyProc</code> is defined in an imported module and that some change occurs to that module outside of our control.  There are two cases:</p>
<ol>
<li><strong>Dereferences get priority.</strong> Then the <code>MyProc</code> changes from not including <code>func</code> to including <code>func</code> (so our client code changes from a direct send to an indirect invoke).</li>
<li><strong>Direct sends get priority.</strong> Then the method <code>func</code> doesn&#8217;t exist initially, but is added later (so our client code changes from an indirect invoke to a direct send).</li>
</ol>
<p>Neither of these options seems desirable &#8230; <em>but what to do?</em></p>
<h2>The Solution?</h2>
<p>Basically, at this stage, I don&#8217;t have a solution &#8230; so suggestions welcome!</p>
<p>One option is to make a clear distinction between dereferencing a field in a record from one in a process.  For example, we could view processes as &#8220;pointers&#8221; to records, and then use C/C++ syntax such as <code>p-&gt;func</code> to indicate we&#8217;re indirectly accessing field <code>func</code> in process <code>p</code>.</p>
<p>What I don&#8217;t like about this approach is the discrepancy between message send and process access syntax.  For example, something like <code>sys.out.println</code> becomes <code>sys-&gt;out.println()</code> (this is a direct message send to the process referenced by field <code>out</code> in the process referenced by <code>sys</code>).</p>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/06/28/disambiguating-ambiguous-syntax/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Whiley v0.3.6 Released!</title>
		<link>http://whiley.org/2011/06/26/whiley-v0-3-6-released/</link>
		<comments>http://whiley.org/2011/06/26/whiley-v0-3-6-released/#comments</comments>
		<pubDate>Sun, 26 Jun 2011 07:06:10 +0000</pubDate>
		<dc:creator>Dave</dc:creator>
				<category><![CDATA[Development]]></category>

		<guid isPermaLink="false">http://whiley.org/?p=2664</guid>
		<description><![CDATA[<p>After an untold number of commits, bug fixes and passing unit tests, the next version of Whiley is released!!  I am trying to lock down the syntax of the language as much as possible now, although there are still a number of open issues.</p> <p>Finally, whilst I&#8217;d love to say &#8220;go and use this <span style="color:#777"> . . . &#8594; Read More: <a href="http://whiley.org/2011/06/26/whiley-v0-3-6-released/">Whiley v0.3.6 Released!</a></span>]]></description>
			<content:encoded><![CDATA[<p>After an untold number of commits, bug fixes and passing unit tests, the next version of Whiley is released!!  I am trying to lock down the syntax of the language as much as possible now, although there are still a number of open issues.</p>
<p>Finally, whilst I&#8217;d love to say &#8220;go and use this version&#8221; &#8230; frankly, you probably shouldn&#8217;t!  There remain quite a few problems, and the benchmark suite doesn&#8217;t even compile.  The switch to using the new bytecode-oriented intermediate language (wyil) was very significant, and it&#8217;ll take a little while to settle down.  Hopefully, the next release will be much sooner &#8230;</p>
<h2>ChangeLog</h2>
<ul>
<li>Changed the Whiley Intermediate Language (Wyil) to be a proper bytecode format.  This simplifies many things, and enables easy implementations of interpreters and virtual machines.</li>
<li>Changed syntax for synchronous and asynchronous message sends from <code>&lt;-&gt;</code> and <code>&lt;-</code> to <code>.</code> and <code>!</code></li>
<li>Changed syntax for top type from <code>*</code> to <code>any</code></li>
<li>Changed syntax for type tests from <code>~=</code> to <code>is</code></li>
<li>Added a first-class <code>string</code> type.  Currently, there is no <code>char</code> type &#8212; this may or may not get added eventually.  The reason for adding this type is to allow for better conversions from data types to strings.  In particular, I want strings to displayed as strings, rather than just lists of integers.</li>
<li>Changed the underlying model of types from the &#8220;ideals&#8221; to the &#8220;reals&#8221;.  See <a href="http://whiley.org/2011/06/20/on-the-duality-of-types-the-ideals-versus-the-reals/">this blog post</a> for more.  As part of this, <code>int</code> values are now implemented as <code>BigIntegers</code> with real types being implemented as <code>BigRationals</code>.</li>
<li>Implemented a simpler, but more complete mechanism for performing type tests.  This is probably slightly less efficient than before, because much of it takes place in the runtime library code rather than being hard-coded into JVM bytecode.</li>
<li>Implemented a simpler approach to performing type coercions, which is based on the mechanism for type tests.  However, I&#8217;m not convinced it&#8217;s actually making things better.</li>
<li>Put in place the basic mechanism for implementing reference counting of compound data structures.  At this stage, I don&#8217;t actually use reference counting &#8230; but that will come soon enough!</li>
</ul>
<h2>To Do Next</h2>
<ul>
<li>Sort out the implicit coercions</li>
<li>Implement complete code for coercions</li>
<li>Add proper first-class tuples to wyil</li>
<li>Fix up problems with function refs, and add support for method refs (and possibly <code>interfaces</code>)</li>
<li>Add support for iterating dictionaries (kind of important)</li>
<li>Fix the <code>multistore</code> bytecode so it&#8217;s a little less chaotic.</li>
<li>Fix problems with <code>fieldload</code>, <code>listload</code>, <code>dictload</code> and effective &#8220;union&#8221; types</li>
<li>Adjust wyil so strong correlation between bytecodes and program statements (probably requires explicit logical not, and, or and xor operators)</li>
<li>Adjust wyil to support &#8220;named&#8221; types to make it a little more human readable (and hopefully to help with error messages as well).</li>
<li>Fix up exceptions: 1) to check for the required throws clause; 2) to support try-catch blocks.</li>
</ul>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/wdk/wdk-src-v0.3.6.tgz" title="Download wdk-src-v0.3.6">wdk-src-v0.3.6</a><br />
      Created on February 7, 2012.  15 Downloads, 954.7 KB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/jar/wyjc-v0.3.6.jar" title="Download wyjc-v0.3.6">wyjc-v0.3.6</a><br />
      Created on February 7, 2012.  42 Downloads, 667.2 KB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
<center>
<div class="wpfilebase-attachment">
 <div class="wpfilebase-rightcol">
  <div class="wpfilebase-filetitle">
   <a href="http://whiley.org/download/bench/wybench-v0.1.2.tgz" title="Download wybench-v0.1.2">wybench-v0.1.2</a><br />
      Created on June 26, 2011.  81 Downloads, 2.2 MB.<br/>
      BSD License
  </div>
 </div>
 <div style="clear: both;"></div>
</div></center>
]]></content:encoded>
			<wfw:commentRss>http://whiley.org/2011/06/26/whiley-v0-3-6-released/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic Page Served (once) in 1.063 seconds -->

