<?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>//FIXME &#187; Meta</title>
	<atom:link href="http://eraserhead.net/category/meta/feed/" rel="self" type="application/rss+xml" />
	<link>http://eraserhead.net</link>
	<description>Jason Felice's blog</description>
	<lastBuildDate>Sat, 04 Sep 2010 03:13:54 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>On Five compilation models for C++</title>
		<link>http://eraserhead.net/2009/08/on-five-compilation-models-for-c/</link>
		<comments>http://eraserhead.net/2009/08/on-five-compilation-models-for-c/#comments</comments>
		<pubDate>Fri, 28 Aug 2009 03:24:13 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[C++]]></category>

		<guid isPermaLink="false">http://eraserhead.net/?p=334</guid>
		<description><![CDATA[Jeff Messner sent me a link to a paper titled Five compilation models for C++.  It describes transforming C++ into an intermediate dynamically-typed language (types are checked at run-time), then possibly using a &#8220;partial evaluator&#8221; to finish the transformation to a statically-checked language.  This C++ compiler is called Lunar.
A few interesting points in [...]]]></description>
			<content:encoded><![CDATA[<p>Jeff Messner sent me a link to a paper titled <a href="http://ubiety.uwaterloo.ca/~tveldhui/papers/2000/tmpw00/index.html">Five compilation models for C++</a>.  It describes transforming C++ into an intermediate dynamically-typed language (types are checked at run-time), then possibly using a &#8220;partial evaluator&#8221; to finish the transformation to a statically-checked language.  This C++ compiler is called <em>Lunar</em>.</p>
<p>A few interesting points in &#8220;the quest for Meta&#8221;:</p>
<h2>Type-Passing Style</h2>
<p>The intermediate code Lunar generates is in <em>type-passing style</em>; new parameters are introduced to functions to carry types.  Assertions are performed on types in non-template code, and other type computations are emitted for template code.  The partial evaluator &#8220;evaluates away&#8221; the type parameters, then should be able to remove them from the final code since they are no longer used.</p>
<p>It&#8217;s interesting that the term &#8220;type-passing style&#8221; has already been coined.  One aspect of the unification of generic programming (which takes types as parameters and returns a function or type) and functional programming (which takes values as parameters and returns a value) which I&#8217;ve been thinking about is unifying the calling syntax.  This would mean that some function could take both value and type arguments, as well as the function could be specialized on the type of value parameters.</p>
<p>It seems, though, that the authors haven&#8217;t hit the &#8220;grand unified theory&#8221; that I&#8217;m trying for, as evidenced by the fact they have chosen to omit the features which are hard.  Take parameter overloading as an example: if types are passed as parameters, then two functions statically dispatched on type have the same &#8217;signature&#8217;.  In C++, you could implement these in different compilation modules, but you can&#8217;t do this in an intermediate language because the compiler would need to implement a centralized dispatch on type with knowledge of all the different implementations &#8211; even if this is later resolved at compile time.</p>
<p>I&#8217;m also thinking about saying, &#8220;Screw it, let&#8217;s throw out the &#8217;sacred cow&#8217; of being able to compile separate &#8216;compilation units&#8217; individually.  Computers have gotten fast, memory is cheap, we can make a compiler which reads all the source, thinks for a while, then spits out <a href="http://www.multivax.com/last_question.html">the answer</a>.&#8221;</p>
<h2>Quadruple Form</h2>
<p>I&#8217;m always curious about new forms for intermediate languages.  This is an area that I haven&#8217;t decided on for Meta just yet, since I need to get a better idea of how the type system will work.  In any case, the intermediate language has a general form called &#8220;quadruple form&#8221;, which is a form where, as the article states:</p>
<blockquote><p>In quadruple form, most instructions are of the form: r <- x1 * x2, where r is a name for the result, x1 and x2 are names or literals, and * is an operator.</p></blockquote>
<p>Interesting, but it doesn&#8217;t appear as powerful as lambda calculus and seems geared for imperative languages.</p>
]]></content:encoded>
			<wfw:commentRss>http://eraserhead.net/2009/08/on-five-compilation-models-for-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Side effects in Meta</title>
		<link>http://eraserhead.net/2009/08/side-effects-in-meta/</link>
		<comments>http://eraserhead.net/2009/08/side-effects-in-meta/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 04:42:46 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Meta]]></category>
		<category><![CDATA[Haskell]]></category>

		<guid isPermaLink="false">http://eraserhead.net/?p=289</guid>
		<description><![CDATA[If Meta is to be the static meta-programming language of choice (I believe Ruby to be the dynamic meta-programming language of choice), we must be able to run lots of user code at compile time.  Let&#8217;s say we have this function:

square&#40;x&#41; = x*x;

If the compiler sees the expression &#8220;square(4)&#8221; in the code, it can [...]]]></description>
			<content:encoded><![CDATA[<p>If Meta is to be the static meta-programming language of choice (I believe Ruby to be the dynamic meta-programming language of choice), we must be able to run lots of user code at compile time.  Let&#8217;s say we have this function:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">square<span style="color: #008000;">&#40;</span>x<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> x<span style="color: #000040;">*</span>x<span style="color: #008080;">;</span></pre></div></div>

<p>If the compiler sees the expression &#8220;square(4)&#8221; in the code, it can replace it with &#8220;16&#8243; at compile time, correct?  Well what about this equivalent function?:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">square<span style="color: #008000;">&#40;</span>x<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">system</span><span style="color: #008000;">&#40;</span><span style="color: #0000dd;">sprintf</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;echo %d*%d |bc&quot;</span>, x, x<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Aha!  Side effects are a problem!  This now gets a lot messier, since the compiler needs to know which functions it can run at compile time and for which functions it must generate run-time instructions.  Language compilers are typically very conservative at estimating this, but this will not do for Meta!</p>
<p>We can say the first function is &#8220;pure&#8221;.  In other words, given the function and the same input parameters, it will produce the same result.  It keeps no internal state and uses no operating system objects such as files or sockets.  In other words, it is not only a computer programming function, it is also a <em>mathematical</em> function.  </p>
<p>Enter the world of the Scheme language for a moment.  By unenforced convention, Scheme functions which mutate objects have names which end with an exclamation point.  They jump out at the programmer, saying &#8220;I&#8217;m actually modifying an object.&#8221;  This isn&#8217;t <em>exactly</em> consistent with the purity concept, but we are going to steal the idiom.  In Meta, all non-pure functions <em>must</em> end with &#8216;!&#8217;.  This not only solves our problem about running user code at compile time, but it allows programmers to reason much better about the code at a glance and helps us with concurrent programming.</p>
<p>The rules are:</p>
<ul>
<li>All impure library functions will be labeled with &#8216;!&#8217;.
<li>Functions labeled with &#8216;!&#8217; aren&#8217;t required to have side effects:

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">g<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span><span style="color: #008080;">;</span> <span style="color: #666666;">// g!() actually has no side effects.  Perhaps it will later.</span></pre></div></div>

<li>Functions which directly call functions labeled with &#8216;!&#8217; must also be labeled with &#8216;!&#8217;.

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">g<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> f<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>  <span style="color: #666666;">// error, g() cannot call f!()</span>
g<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> f<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> <span style="color: #666666;">// OK, g!() can call f!()</span></pre></div></div>

<li>Impure functions may not be passed to functions which don&#8217;t expect them.

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// OK, h is pure</span>
let f<span style="color: #008000;">&#40;</span>g<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> g<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> in
let h<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> in
f<span style="color: #008000;">&#40;</span>h<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span> 
&nbsp;
<span style="color: #666666;">// Compile error</span>
let f<span style="color: #008000;">&#40;</span>g<span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> g<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> in
let h<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> in
f<span style="color: #008000;">&#40;</span>h<span style="color: #000040;">!</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// OK, f(g!) indicates that g! can be impure.  Note that we</span>
<span style="color: #666666;">// haven't labeled f because it doesn't actually invoke g!.</span>
let f<span style="color: #008000;">&#40;</span>g<span style="color: #000040;">!</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> g<span style="color: #000040;">!</span> in
let h<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> in
f<span style="color: #008000;">&#40;</span>h<span style="color: #000040;">!</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// OK, now we must label f</span>
let f<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span>g<span style="color: #000040;">!</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> g<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> in
let h<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> in
f<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span>h<span style="color: #000040;">!</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// We can always pass a pure function where an impure one is acceptable.</span>
let f<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span>g<span style="color: #000040;">!</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> g<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> in
let h<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> in
f<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span>h<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<li>Functions whose purity depends on the parameters passed may annotate parameters with &#8216;!?&#8217;.  In these cases, the function itself need not be annotated with &#8216;!&#8217;, but whether a particular invocation will require the enclosing function to be labeled will be determined from the parameters passed.

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// This expression does not require the function containing it</span>
<span style="color: #666666;">// to be labeled with '!'.</span>
let h<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> in
let f<span style="color: #008000;">&#40;</span>g<span style="color: #000040;">!</span><span style="color: #008080;">?</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> g<span style="color: #000040;">!</span><span style="color: #008080;">?</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> in
f<span style="color: #008000;">&#40;</span>h<span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// This expression does.</span>
let h<span style="color: #000040;">!</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> <span style="color: #0000dd;">0</span> in
let f<span style="color: #008000;">&#40;</span>g<span style="color: #000040;">!</span><span style="color: #008080;">?</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">=</span> g<span style="color: #000040;">!</span><span style="color: #008080;">?</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> in
f<span style="color: #008000;">&#40;</span>h<span style="color: #000040;">!</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

</ul>
]]></content:encoded>
			<wfw:commentRss>http://eraserhead.net/2009/08/side-effects-in-meta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Beginnings of Meta</title>
		<link>http://eraserhead.net/2009/08/the-beginnings-of-meta/</link>
		<comments>http://eraserhead.net/2009/08/the-beginnings-of-meta/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 16:15:43 +0000</pubDate>
		<dc:creator>Jason</dc:creator>
				<category><![CDATA[Meta]]></category>

		<guid isPermaLink="false">http://eraserhead.net/?p=286</guid>
		<description><![CDATA[I&#8217;ve long been a connoisseur of programming languages, hacking on just about anything I can get my hands on from Io to D, from Objective CAML to Haskell, and from Scheme to PostScript to Erlang.  I&#8217;ve just finished getting familiar with Erlang, and I can&#8217;t help it now, I find myself picking at its [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve long been a connoisseur of programming languages, hacking on just about anything I can get my hands on from Io to D, from Objective CAML to Haskell, and from Scheme to PostScript to Erlang.  I&#8217;ve just finished getting familiar with Erlang, and I can&#8217;t help it now, I find myself picking at its syntax rules (anonymous functions are a bulky construct, and must be bound to variable names starting with a capital letter, providing a weird dichotomy between module functions and anonymous functions).  Don&#8217;t get me wrong: Erlang is definitely a good language.</p>
<p>And so, I have decided that I must write a language.  I expect this to be a many-year personal endeavor, but a lot of these language complaints I have on a recurring basis, and I suspect starting a language should have a lot more influence than simply complaining.</p>
<p>The language is tenatively named &#8220;Meta&#8221;.  C++ provides rich meta-programming support in a statically typed environment; however, it falls down in many different ways and this rich support has never been successfully exported to another language.  Meta intends to export this rich meta-programming support to a functional language (which is a different beast, so we aren&#8217;t just trying to &#8220;fix C++&#8221;).</p>
<p>Meta will be compiled, statically-typed, and functional.  It will not be lazy.  Objects will be immutable.  It should be able to write safely concurrent programs, and should be usable in large projects by multiple developers, meaning that it should be pragmatic.</p>
<p>I will make a series of posts on design decisions for Meta, and I ask for feedback and input.</p>
]]></content:encoded>
			<wfw:commentRss>http://eraserhead.net/2009/08/the-beginnings-of-meta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
