<?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>Learning After School</title>
	<atom:link href="http://blog.sw17ch.com/wordpress/?feed=rss2" rel="self" type="application/rss+xml" />
	<link>http://blog.sw17ch.com/wordpress</link>
	<description>You don&#039;t get to stop learning when you graduate.</description>
	<lastBuildDate>Mon, 19 Jul 2010 16:06:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Hypothetically speaking&#8230;</title>
		<link>http://blog.sw17ch.com/wordpress/?p=216</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=216#comments</comments>
		<pubDate>Mon, 19 Jul 2010 16:06:47 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=216</guid>
		<description><![CDATA[Hypothetically speaking&#8230; &#8230; if you were working on a language which was in many ways similar to (and targets) C but added more expressive types, type inference, and polymorphism, how would you interpret the following line of code? x = &#34;foo&#34;; The options are: char x&#91;&#93; = &#34;foo&#34;; or char * x = &#34;foo&#34;; Thoughts?]]></description>
			<content:encoded><![CDATA[<p>Hypothetically speaking&#8230;</p>
<p>&#8230; if you were working on a language which was in many ways similar to (and targets) C but added more expressive types, type inference, and polymorphism, how would you interpret the following line of code?</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;">x <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;foo&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>The options are:</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> x<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;foo&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>or</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #993333;">char</span> <span style="color: #339933;">*</span> x <span style="color: #339933;">=</span> <span style="color: #ff0000;">&quot;foo&quot;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=216</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Do Yourself a Favor</title>
		<link>http://blog.sw17ch.com/wordpress/?p=208</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=208#comments</comments>
		<pubDate>Wed, 23 Jun 2010 21:34:28 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=208</guid>
		<description><![CDATA[Stick this in your .bashrc: export HISTCONTROL=erasedups export HISTSIZE=500 export HISTIGNORE=ls:'ls -l':fg This changes what gets shoved into .bash_history. Erase duplicate entires that have shown up previously. Set the history size to 500 Ignore a few specified commands]]></description>
			<content:encoded><![CDATA[<p>Stick this in your .bashrc:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTCONTROL</span>=erasedups
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTSIZE</span>=<span style="color: #000000;">500</span>
<span style="color: #7a0874; font-weight: bold;">export</span> <span style="color: #007800;">HISTIGNORE</span>=<span style="color: #c20cb9; font-weight: bold;">ls</span>:<span style="color: #ff0000;">'ls -l'</span>:<span style="color: #7a0874; font-weight: bold;">fg</span></pre></div></div>

<p>This changes what gets shoved into .bash_history.</p>
<ul>
<li>Erase duplicate entires that have shown up previously.</li>
<li>Set the history size to 500</li>
<li>Ignore a few specified commands</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=208</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Thought for Today</title>
		<link>http://blog.sw17ch.com/wordpress/?p=203</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=203#comments</comments>
		<pubDate>Wed, 20 Jan 2010 17:28:57 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=203</guid>
		<description><![CDATA[Just one thing: MERGING IS HARD. That is all.]]></description>
			<content:encoded><![CDATA[<p>Just one thing:</p>
<p><strong>MERGING IS HARD.</strong></p>
<p>That is all.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=203</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>More Arduino</title>
		<link>http://blog.sw17ch.com/wordpress/?p=200</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=200#comments</comments>
		<pubDate>Wed, 13 Jan 2010 15:40:32 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=200</guid>
		<description><![CDATA[I just ordered my own an Arduino Duemilanove! I&#8217;ve been borrowing Job&#8217;s Arduino up until now (thanks Job). I&#8217;ve got some plans for a few more interesting posts using Atom on the Arduino when this thing arrives. SparkFun Electronics &#8211; Arduino USB Board]]></description>
			<content:encoded><![CDATA[<p>I just ordered my own an Arduino Duemilanove! I&#8217;ve been borrowing Job&#8217;s Arduino up until now (thanks <a href="http://humanconstraints.com/">Job</a>). I&#8217;ve got some plans for a few more interesting posts using Atom on the Arduino when this thing arrives.</p>
<p><a href="http://www.sparkfun.com/commerce/product_info.php?products_id=666">SparkFun Electronics &#8211; Arduino USB Board</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=200</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Moved!</title>
		<link>http://blog.sw17ch.com/wordpress/?p=176</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=176#comments</comments>
		<pubDate>Wed, 06 Jan 2010 03:29:47 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[moving]]></category>

		<guid isPermaLink="false">http://meebit.com/blog/wordpress/?p=176</guid>
		<description><![CDATA[Hi everyone. I moved this blog from http://angryhosting.com/ to a VPS hosted with http://linode.com/. I know a bunch of links now target this site, so I&#8217;ve done my best to maintain all the old links and files, etc. If any one notices problems with the old posts (broken links or otherwise), let me know. Thanks.]]></description>
			<content:encoded><![CDATA[<p>Hi everyone.</p>
<p>I moved this blog from http://angryhosting.com/ to a VPS hosted with http://linode.com/. I know a bunch of links now target this site, so I&#8217;ve done my best to maintain all the old links and files, etc.</p>
<p>If any one notices problems with the old posts (broken links or otherwise), let me know.</p>
<p>Thanks.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=176</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>HsOpenSSL Update</title>
		<link>http://blog.sw17ch.com/wordpress/?p=155</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=155#comments</comments>
		<pubDate>Sat, 27 Jun 2009 17:27:49 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=155</guid>
		<description><![CDATA[The maintainer of HsOpenSSL accepted a patch Job Vranish and I put together that moves to a simple build type rather than the configure step. This has the nice side effect that, with the right libraries installed, we can get HsOpenSSL to install happily in windows without the need for Cygwin to build it. Here&#8217;s [...]]]></description>
			<content:encoded><![CDATA[<p>The maintainer of HsOpenSSL accepted a patch Job Vranish and I put together that moves to a simple build type rather than the configure step. This has the nice side effect that, with the right libraries installed, we can get HsOpenSSL to install happily in windows without the need for Cygwin to build it.</p>
<p>Here&#8217;s how:</p>
<ol>
<li> First, we need to install the OpenSSL binaries and header files. The Windows build of OpenSSL depends on the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF">Visual C++ 2008 Redistributables</a>. Download and install them.</li>
<li> Next we need the <a href="http://www.slproweb.com/download/Win32OpenSSL-0_9_8l.exe">Win32 OpenSSL v0.9.8k</a> package. Download and install this.</li>
<li> Open cmd.exe to run a few commands.</li>
<li> Now that OpenSSL is installed, lets perform a <code>cabal update</code> to make sure we have the most recent package.</li>
<li> If you used the default installation options, you can call the following command to install HsOpenSSL:<code><br />
cabal install --reinstall HsOpenSSL --extra-include-dirs=C:\OpenSSL\include --extra-lib-dirs=C:\OpenSSL\lib\MinGW<br />
</code></p>
<p>Note that I included <code>--reinstall</code> just to make sure we don&#8217;t terminate prematurely because of an older version.</li>
</ol>
<p>Everything should be installed now. Lets test it. Save this into a file somewhere:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> OpenSSL<span style="color: #339933; font-weight: bold;">.</span>RSA
&nbsp;
main <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">IO</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    key <span style="color: #339933; font-weight: bold;">&lt;-</span> generateRSAKey' <span style="color: red;">2048</span> <span style="color: red;">65537</span>
&nbsp;
    <span style="font-weight: bold;">print</span> key</pre></div></div>

<p>And lets build it&#8230;</p>
<p><code>ghc --make test.hs</code></p>
<p>&#8230;and run it&#8230;</p>
<p><code>&gt;test.exe<br />
RSAKeyPair {rsaN = [ZOMG BIG NUMBER], rsaE = 65537, rsaD = [ZOMG ANOTHER ONE], rsaP = [THIS ONE WASN'T AS LARGE], rsaQ = [SAME HERE, BUT STILL PRETTY HUGE] }</code></p>
<p>If you got some output that wasn&#8217;t an error from test.exe, you&#8217;ve successfully installed HsOpenSSL in Windows.</p>
<p>Hope this helps someone!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=155</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Data.Binary and Byte Order</title>
		<link>http://blog.sw17ch.com/wordpress/?p=141</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=141#comments</comments>
		<pubDate>Fri, 29 May 2009 03:13:19 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[haskell]]></category>
		<category><![CDATA[Data.Binary]]></category>
		<category><![CDATA[endian]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=141</guid>
		<description><![CDATA[I seem to come across the (false) idea that Data.Binary isn&#8217;t able to handle encoding/decoding things of non-network byte order. So, for all those of you who are trying to get Data.Binary to use little endian instead of big endian, consider this a guide. Lets build a small module that encodes and decodes a simple [...]]]></description>
			<content:encoded><![CDATA[<p>I seem to come across the (false) idea that Data.Binary isn&#8217;t able to handle encoding/decoding things of non-network byte order. So, for all those of you who are trying to get Data.Binary to use little endian instead of big endian, consider this a guide.</p>
<p>Lets build a small module that encodes and decodes a simple <code>data</code>.</p>
<p>Module and imports first!</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Text<span style="color: #339933; font-weight: bold;">.</span>Printf
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Binary
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Binary<span style="color: #339933; font-weight: bold;">.</span>Get
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Binary<span style="color: #339933; font-weight: bold;">.</span>Put
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>ByteString<span style="color: #339933; font-weight: bold;">.</span>Lazy <span style="color: #06c; font-weight: bold;">hiding</span> <span style="color: green;">&#40;</span><span style="font-weight: bold;">concatMap</span><span style="color: #339933; font-weight: bold;">,</span> <span style="font-weight: bold;">putStrLn</span><span style="color: green;">&#41;</span></pre></div></div>

<p>Lets describe the type we&#8217;re going to encode/decode.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> Foo <span style="color: #339933; font-weight: bold;">=</span> Foo <span style="color: green;">&#123;</span>
    w16 <span style="color: #339933; font-weight: bold;">::</span> Word16<span style="color: #339933; font-weight: bold;">,</span>
    w32 <span style="color: #339933; font-weight: bold;">::</span> Word32<span style="color: #339933; font-weight: bold;">,</span>
    w64 <span style="color: #339933; font-weight: bold;">::</span> Word64
<span style="color: green;">&#125;</span> <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Read</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>

<p>I&#8217;d like to be able to represent this as both big endian and little endian, so I&#8217;m making two <code>newtype</code> wrappers:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- Foo, Little Endian</span>
<span style="color: #06c; font-weight: bold;">newtype</span> FooLE <span style="color: #339933; font-weight: bold;">=</span> FooLE <span style="color: green;">&#123;</span> unFooLE <span style="color: #339933; font-weight: bold;">::</span> Foo <span style="color: green;">&#125;</span>
  <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Read</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span>
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Foo, Big Endian</span>
<span style="color: #06c; font-weight: bold;">newtype</span> FooBE <span style="color: #339933; font-weight: bold;">=</span> FooBE <span style="color: green;">&#123;</span> unFooBE <span style="color: #339933; font-weight: bold;">::</span> Foo <span style="color: green;">&#125;</span>
  <span style="color: #06c; font-weight: bold;">deriving</span> <span style="color: green;">&#40;</span><span style="color: #cccc00; font-weight: bold;">Read</span><span style="color: #339933; font-weight: bold;">,</span><span style="color: #cccc00; font-weight: bold;">Show</span><span style="color: green;">&#41;</span></pre></div></div>

<p>Now for the instances! Lets do little endian first (since it seems to be the most problematic):</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> Binary FooLE <span style="color: #06c; font-weight: bold;">where</span>
    get <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
        w16le <span style="color: #339933; font-weight: bold;">&lt;-</span> getWord16le
        w32le <span style="color: #339933; font-weight: bold;">&lt;-</span> getWord32le
        w64le <span style="color: #339933; font-weight: bold;">&lt;-</span> getWord64le
        <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> FooLE <span style="color: #339933; font-weight: bold;">$</span> Foo <span style="color: green;">&#123;</span> w16 <span style="color: #339933; font-weight: bold;">=</span> w16le<span style="color: #339933; font-weight: bold;">,</span>
                               w32 <span style="color: #339933; font-weight: bold;">=</span> w32le<span style="color: #339933; font-weight: bold;">,</span>
                               w64 <span style="color: #339933; font-weight: bold;">=</span> w64le <span style="color: green;">&#125;</span>
    put fle <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
        <span style="color: #06c; font-weight: bold;">let</span> f <span style="color: #339933; font-weight: bold;">=</span> unFooLE fle
        putWord16le <span style="color: #339933; font-weight: bold;">$</span> w16 f
        putWord32le <span style="color: #339933; font-weight: bold;">$</span> w32 f
        putWord64le <span style="color: #339933; font-weight: bold;">$</span> w64 f</pre></div></div>

<p>Note that <code>putWordXXle</code> and <code>getWordXXle</code> are found in <code>Data.Binary.{Get,Put}</code>&#8211;they aren&#8217;t exposed by <code>Data.Binary</code> (perhaps they should be?).</p>
<p>What&#8217;s going on here? In the <code>get</code> instance, we simple pull bytes off using the little endian functions, make a <code>Foo</code>, and wrap it in a <code>FooLE</code>!</p>
<p>The <code>put</code> instance unwraps <code>Foo</code> and uses the record selectors of <code>Foo</code> to hand stuff to the <code>put*</code> functions.</p>
<p>The big endian version is nearly identical:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">instance</span> Binary FooBE <span style="color: #06c; font-weight: bold;">where</span>
    get <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
        w16be <span style="color: #339933; font-weight: bold;">&lt;-</span> getWord16be
        w32be <span style="color: #339933; font-weight: bold;">&lt;-</span> getWord32be
        w64be <span style="color: #339933; font-weight: bold;">&lt;-</span> getWord64be
        <span style="font-weight: bold;">return</span> <span style="color: #339933; font-weight: bold;">$</span> FooBE <span style="color: #339933; font-weight: bold;">$</span> Foo <span style="color: green;">&#123;</span> w16 <span style="color: #339933; font-weight: bold;">=</span> w16be<span style="color: #339933; font-weight: bold;">,</span>
                               w32 <span style="color: #339933; font-weight: bold;">=</span> w32be<span style="color: #339933; font-weight: bold;">,</span>
                               w64 <span style="color: #339933; font-weight: bold;">=</span> w64be <span style="color: green;">&#125;</span>
    put fbe <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
        <span style="color: #06c; font-weight: bold;">let</span> f <span style="color: #339933; font-weight: bold;">=</span> unFooBE fbe
        putWord16be <span style="color: #339933; font-weight: bold;">$</span> w16 f
        putWord32be <span style="color: #339933; font-weight: bold;">$</span> w32 f
        putWord64be <span style="color: #339933; font-weight: bold;">$</span> w64 f</pre></div></div>

<p>Again, we look for the <code>put*</code> and get* functions in <code>Data.Binary.{Put,Get}</code>.</p>
<p>Now we just need to create some test data, make a function to print the hex string (so that we know that we output the bytes in the right order), and encode/decode/print the test data to ensure things come back the right way.</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">td <span style="color: #339933; font-weight: bold;">::</span> Foo
td <span style="color: #339933; font-weight: bold;">=</span> Foo <span style="color: green;">&#123;</span> w16 <span style="color: #339933; font-weight: bold;">=</span> 0x0011<span style="color: #339933; font-weight: bold;">,</span>
           w32 <span style="color: #339933; font-weight: bold;">=</span> 0x00112233<span style="color: #339933; font-weight: bold;">,</span>
           w64 <span style="color: #339933; font-weight: bold;">=</span> 0x0011223344556677 <span style="color: green;">&#125;</span>
&nbsp;
tdBE <span style="color: #339933; font-weight: bold;">::</span> FooBE
tdBE <span style="color: #339933; font-weight: bold;">=</span> FooBE td
&nbsp;
tdLE <span style="color: #339933; font-weight: bold;">::</span> FooLE
tdLE <span style="color: #339933; font-weight: bold;">=</span> FooLE td
&nbsp;
printHex <span style="color: #339933; font-weight: bold;">::</span> ByteString <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
printHex b <span style="color: #339933; font-weight: bold;">=</span> <span style="font-weight: bold;">concatMap</span> <span style="color: green;">&#40;</span>printf <span style="background-color: #3cb371;">&quot;%02x&quot;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">$</span> unpack b
&nbsp;
main <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">IO</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
main <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: #06c; font-weight: bold;">let</span> le  <span style="color: #339933; font-weight: bold;">=</span> encode <span style="color: #339933; font-weight: bold;">$</span> tdLE
        be  <span style="color: #339933; font-weight: bold;">=</span> encode <span style="color: #339933; font-weight: bold;">$</span> tdBE
        le' <span style="color: #339933; font-weight: bold;">=</span> decode <span style="color: #339933; font-weight: bold;">$</span> le <span style="color: #339933; font-weight: bold;">::</span> FooLE
        be' <span style="color: #339933; font-weight: bold;">=</span> decode <span style="color: #339933; font-weight: bold;">$</span> be <span style="color: #339933; font-weight: bold;">::</span> FooBE
&nbsp;
    <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;le:&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span>printHex le<span style="color: green;">&#41;</span>
    <span style="font-weight: bold;">print</span> le'
&nbsp;
    <span style="font-weight: bold;">putStrLn</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="background-color: #3cb371;">&quot;be:&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> <span style="color: green;">&#40;</span>printHex be<span style="color: green;">&#41;</span>
    <span style="font-weight: bold;">print</span> be'</pre></div></div>

<p>What&#8217;s the output?</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">le:1100332211007766554433221100
FooLE {unFooLE = Foo {w16 = 17, w32 = 1122867, w64 = 4822678189205111}}
be:0011001122330011223344556677
FooBE {unFooBE = Foo {w16 = 17, w32 = 1122867, w64 = 4822678189205111}}</pre></div></div>

<p>Now, lets try and get over the idea that you can&#8217;t <em>easily</em> use Data.Binary to play with byte order. It&#8217;s rather trivial. <img src='http://blog.sw17ch.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=141</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Atom &amp; Arduino :: First Program (pt. 2)</title>
		<link>http://blog.sw17ch.com/wordpress/?p=111</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=111#comments</comments>
		<pubDate>Tue, 05 May 2009 03:58:35 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[atom]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=111</guid>
		<description><![CDATA[Last time we talked about a few changes I made to Atom. This time we&#8217;re going to start writing some programs. Our first one will be pretty simple. First, we need a short C file (this is the only C code, besides the #include&#8216;s and the prototype we use in blink.h, we need to write [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://blog.sw17ch.com/wordpress/?p=84">Last time</a> we talked about a few changes I made to Atom. This time we&#8217;re going to start writing some programs. Our first one will be pretty simple.</p>
<p>First, we need a short <a href="http://code.sw17ch.com/blog/atom/blink.c">C file</a> (this is the only C code, besides the <code>#include</code>&#8216;s and the prototype we use in <code>blink.h</code>, we need to write our selves):</p>

<div class="wp_syntax"><div class="code"><pre class="c" style="font-family:monospace;"><span style="color: #339933;">#include &quot;blink.h&quot;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* PORTB corresponds some how to Pin 13. We get
 * a blinking LED on the board. We can also plug
 * an LED into Pin 13 and the GND pins. */</span>
<span style="color: #993333;">void</span> setLED<span style="color: #009900;">&#40;</span>uint8_t value<span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    PORTB <span style="color: #339933;">=</span> <span style="color: #208080;">0xFF</span> <span style="color: #339933;">*</span> <span style="color: #339933;">!!</span>value<span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #808080; font-style: italic;">/* main only needs to continously call blink_atom(). */</span>
<span style="color: #993333;">int</span> main<span style="color: #009900;">&#40;</span><span style="color: #993333;">int</span> argc<span style="color: #339933;">,</span> <span style="color: #993333;">char</span> <span style="color: #339933;">*</span> argv<span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">while</span><span style="color: #009900;">&#40;</span><span style="color: #0000dd;">1</span><span style="color: #009900;">&#41;</span>
    <span style="color: #009900;">&#123;</span>
        blink_atom<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>Next, lets make <code>Main</code> in our Haskell file, pull in some modules, and define the AtomConfig:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">module</span> Main <span style="color: #06c; font-weight: bold;">where</span>
&nbsp;
<span style="color: #06c; font-weight: bold;">import</span> Language<span style="color: #339933; font-weight: bold;">.</span>Atom
<span style="color: #06c; font-weight: bold;">import</span> Data<span style="color: #339933; font-weight: bold;">.</span>Word
&nbsp;
<span style="color: #5d478b; font-style: italic;">-- Override some default values</span>
cfg <span style="color: #339933; font-weight: bold;">=</span> AtomConfig <span style="color: green;">&#123;</span>
    <span style="color: #5d478b; font-style: italic;">-- This pulls some stuff in we use below.</span>
    cIncludes <span style="color: #339933; font-weight: bold;">=</span> Just <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;blink.h&quot;</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- The (u)intXX_t types are defined in</span>
    <span style="color: #5d478b; font-style: italic;">-- stdint.h--which we include from blink.h</span>
    cTyper    <span style="color: #339933; font-weight: bold;">=</span> Just <span style="color: #339933; font-weight: bold;">$</span> \t <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">case</span> t <span style="color: #06c; font-weight: bold;">of</span>
                                <span style="color: #cccc00; font-weight: bold;">Bool</span>   <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint8_t&quot;</span>
                                Int8   <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int8_t&quot;</span>
                                Int16  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int16_t&quot;</span>
                                Int32  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int32_t&quot;</span>
                                Int64  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int64_t&quot;</span>
                                Word8  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint8_t&quot;</span>
                                Word16 <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint16_t&quot;</span>
                                Word32 <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint32_t&quot;</span>
                                Word64 <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint64_t&quot;</span>
                                <span style="color: #cccc00; font-weight: bold;">Float</span>  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;float&quot;</span>
                                <span style="color: #cccc00; font-weight: bold;">Double</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;double&quot;</span>
<span style="color: green;">&#125;</span></pre></div></div>

<p>We reference the C include file <a href="http://code.sw17ch.com/blog/atom/blink.h">blink.h</a>. This is here to pull in some utility AVR chip utility functions and &#8220;stdint.h&#8221; (which defines <code>uint8_t</code> and friends). We also prototype the <code>blink_atom</code> function Atom will eventually define. We&#8217;ll go over what to do with this in just a bit.</p>
<p>Next we define main:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- Main just has to compile the Atom expression</span>
main <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">IO</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
main <span style="color: #339933; font-weight: bold;">=</span> compile <span style="background-color: #3cb371;">&quot;blink_atom&quot;</span> <span style="color: green;">&#40;</span>Just cfg<span style="color: green;">&#41;</span> blink</pre></div></div>

<p>Remember that the version of <code>compile</code> used here is not the version included with atom-0.0.2. This is the altered version we discussed earlier.</p>
<p>The first argument tells Atom what to name the top level function&#8211;in this case, <code>blink_atom</code>. You&#8217;ll notice that this was the function prototyped in <code>blink.h</code>. Secondly, we pass the  config we just defined. If one does not wish to define any include files or override the default C types, it&#8217;s perfectly fine to pass Nothing here instead&#8211;the defaults will be used.</p>
<p>The last argument, <code>blink</code>, is the name of the <code>Atom ()</code>&#8211;the type used to describe our system&#8211;we&#8217;re about to define.</p>
<p>Lets take a look at that:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- Simple Atom to toggle an LED</span>
blink <span style="color: #339933; font-weight: bold;">::</span> Atom <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
blink <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span>
    <span style="color: #5d478b; font-style: italic;">-- Is the LED currently on? (Assume it starts False/off)</span>
    isOn    <span style="color: #339933; font-weight: bold;">&lt;-</span> bool <span style="background-color: #3cb371;">&quot;isOn&quot;</span> False
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- Does the toggle counter need a reset? (Assume it starts False/no)</span>
    doReset <span style="color: #339933; font-weight: bold;">&lt;-</span> bool <span style="background-color: #3cb371;">&quot;doReset&quot;</span> False
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- Initialize the toggle counter to delayCycles</span>
    toggle  <span style="color: #339933; font-weight: bold;">&lt;-</span> word16 <span style="background-color: #3cb371;">&quot;toggle&quot;</span> delayCycles
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- Decrements the toggle counter when it</span>
    <span style="color: #5d478b; font-style: italic;">-- is greater than 0.</span>
    period <span style="color: red;">1</span> <span style="color: #339933; font-weight: bold;">$</span> atom <span style="background-color: #3cb371;">&quot;decrement&quot;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: #06c; font-weight: bold;">do</span>
        cond <span style="color: #339933; font-weight: bold;">$</span> value toggle <span style="color: #339933; font-weight: bold;">&gt;.</span> <span style="color: red;">0</span>
        toggle <span style="color: #339933; font-weight: bold;">&lt;==</span> value toggle <span style="color: #339933; font-weight: bold;">-</span> <span style="color: red;">1</span>
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- Checks if we need to perform a toggle</span>
    <span style="color: #5d478b; font-style: italic;">-- reset, and performs it when we need one.</span>
    period <span style="color: red;">2</span> <span style="color: #339933; font-weight: bold;">$</span> atom <span style="background-color: #3cb371;">&quot;reset&quot;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: #06c; font-weight: bold;">do</span>
        cond <span style="color: #339933; font-weight: bold;">$</span> value doReset
        doReset <span style="color: #339933; font-weight: bold;">&lt;==</span> Const False
        toggle  <span style="color: #339933; font-weight: bold;">&lt;==</span> Const delayCycles
&nbsp;
    <span style="color: #5d478b; font-style: italic;">-- Checks if the toggle counter has expired.</span>
    <span style="color: #5d478b; font-style: italic;">-- Toggles the LED if it has, then requests</span>
    <span style="color: #5d478b; font-style: italic;">-- a reset.</span>
    period <span style="color: red;">2</span> <span style="color: #339933; font-weight: bold;">$</span> atom <span style="background-color: #3cb371;">&quot;flip&quot;</span> <span style="color: #339933; font-weight: bold;">$</span> <span style="color: #06c; font-weight: bold;">do</span>
        cond <span style="color: #339933; font-weight: bold;">$</span> value toggle <span style="color: #339933; font-weight: bold;">&lt;=.</span> <span style="color: red;">0</span>
        setLED isOn
        isOn <span style="color: #339933; font-weight: bold;">&lt;==</span> <span style="color: green;">&#40;</span>not<span style="color: #339933; font-weight: bold;">_</span> <span style="color: #339933; font-weight: bold;">$</span> value isOn<span style="color: green;">&#41;</span>
        doReset <span style="color: #339933; font-weight: bold;">&lt;==</span> Const True</pre></div></div>

<p><code>cond</code> acts as a guard. It ensures that the boolean statement passed to it is true before allowing the rest of the atom to execute. <code><==</code> is the assignment operator. We'll discuss <code>period</code> in more depth later, but for now, you just need to know that something with a period of 2 will run every other tick<sup class='footnote'><a href='#fn-111-1' id='fnref-111-1'>1</a></sup> through the system whereas something with a period of 3 will run every third tick.</p>
<p><code>delayCycles</code> refers to the number of cycles through the main loop we want to wait before toggling the state of the LED. Since this particular CPU is running at about 16Mhz, we define this as some relatively large number:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- How many cycles do we want to delay before</span>
<span style="color: #5d478b; font-style: italic;">-- we flip the LED?</span>
delayCycles <span style="color: #339933; font-weight: bold;">::</span> Word16
delayCycles <span style="color: #339933; font-weight: bold;">=</span> <span style="color: red;">30000</span></pre></div></div>

<p><code>setLED</code> describes how to call the corresponding <code>setLED</code> C function we defined in <code>blink.c</code>. Lets look at the type signature of <code>action</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">action <span style="color: #339933; font-weight: bold;">::</span> <span style="color: green;">&#40;</span><span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>UE<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Atom <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></pre></div></div>

<p>So, it expects, for its first argument, a function which takes a list of <code>String</code>s and returns a <code>String</code>. Its second is a list of "untyped expressions", and it produces an <code>Atom</code>.</p>
<p>Atom takes the list of UE's, converts them into the C symbols (often times something like "e1" or "e2"), and then passes them to the provided function for inclusion in some C statment. We can see this at work in the code snippet below:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #5d478b; font-style: italic;">-- An action (basically raw C code) to set the value</span>
<span style="color: #5d478b; font-style: italic;">-- of the LED. setLED() is defined in blink.c.</span>
setLED <span style="color: #339933; font-weight: bold;">::</span> V <span style="color: #cccc00; font-weight: bold;">Bool</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> Atom <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span>
setLED v <span style="color: #339933; font-weight: bold;">=</span> action <span style="color: green;">&#40;</span>\<span style="color: green;">&#91;</span>x<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;setLED(&quot;</span> <span style="color: #339933; font-weight: bold;">++</span> x <span style="color: #339933; font-weight: bold;">++</span> <span style="background-color: #3cb371;">&quot;)&quot;</span><span style="color: green;">&#41;</span> <span style="color: green;">&#91;</span>v'<span style="color: green;">&#93;</span>
    <span style="color: #06c; font-weight: bold;">where</span> v' <span style="color: #339933; font-weight: bold;">=</span> ue <span style="color: #339933; font-weight: bold;">.</span> value <span style="color: #339933; font-weight: bold;">$</span> v</pre></div></div>

<p>Here, we take a Bool, and we pass it to the <code>setLED</code> function, which, presumably, turns the LED on when True, and turns it off when False.</p>
<p>This has been a brief discussion of the Haskell code needed to generate the C code for the Arduino board. Next time, we'll investigate the C code that was generated (along with some other artifacts) and how they correspond to the Haskell we have written.</p>
<p>Here are links to the files we've dicussed today:</p>
<ul>
<li><a href="http://code.sw17ch.com/blog/atom/blink.h">blink.h</a></li>
<li><a href="http://code.sw17ch.com/blog/atom/blink.c">blink.c</a></li>
<li><a href="http://code.sw17ch.com/blog/atom/blink.hs">blink.hs</a></li>
<li><a href="http://code.sw17ch.com/blog/atom/blink_atom.c">blink_atom.c</a> (This is the generated code. Consider it a sneak peek at next time.)</li>
</ul>
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-111-1'>A tick is a single call to the <code>blink_atom</code> which is the top level Atom function. <span class='footnotereverse'><a href='#fnref-111-1'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=111</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Atom &amp; Arduino :: Some Hacking (pt. 1)</title>
		<link>http://blog.sw17ch.com/wordpress/?p=84</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=84#comments</comments>
		<pubDate>Fri, 01 May 2009 12:39:13 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Distraction]]></category>
		<category><![CDATA[atom]]></category>
		<category><![CDATA[haskell]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=84</guid>
		<description><![CDATA[Hacking some atom and making stuff play nice on an Arduino.]]></description>
			<content:encoded><![CDATA[<p>When <a href="http://haskell.org/pipermail/haskell-cafe/2009-April/060602.html">Tom Hawkins released</a> the <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/atom">Atom package</a>, I stole my friend&#8217;s Arduino <a href="http://arduino.cc/en/Main/ArduinoBoardDiecimila">Diecimila</a> to see if I could get some Atom-generated code to work. Turns out it wasn&#8217;t that hard!  I&#8217;ll be detailing this in the next few posts. I&#8217;m going to use this first post to point out two things I changed in atom-0.0.2.</p>
<ul>
<li>By default, Atom hardcodes the C types which correspond to the Atom types. This means that an <code>Int32</code> is always defined as <code>signed int</code>. Unfortunately, the ATmega168 CPU and the <a href="http://www.avrfreaks.net/wiki/index.php/Documentation:AVR_GCC">avr-gcc</a> compiler define a <code>signed int</code> as an <code>Int16</code>. I needed a way to customize these types.</li>
<li>Even though an Atom <a href="http://hackage.haskell.org/packages/archive/atom/0.0.2/doc/html/Language-Atom-Language.html#v%3Aaction"><code>action</code></a> can refer to an external function, I wasn&#8217;t able to see a nice way to have Atom plop a <code>#include</code> in the generated code. I added this ability as well.</li>
</ul>
<p>My changes only end up affecting two exposed functions. To facilitate the include files and the C types, I added an <code>AtomConfig</code> data type (this can be found in Language.Atom.Code).</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;"><span style="color: #06c; font-weight: bold;">data</span> AtomConfig <span style="color: #339933; font-weight: bold;">=</span> AtomConfig <span style="color: green;">&#123;</span>
    cIncludes <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Maybe</span> <span style="color: green;">&#91;</span><span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span>
    cTyper    <span style="color: #339933; font-weight: bold;">::</span> <span style="color: #cccc00; font-weight: bold;">Maybe</span> <span style="color: green;">&#40;</span>Type <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span><span style="color: green;">&#41;</span>
<span style="color: green;">&#125;</span></pre></div></div>

<p>I also changed the type signature of <code>writeC</code>. It now reads as:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">writeC <span style="color: #339933; font-weight: bold;">::</span> Name <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Maybe</span> AtomConfig <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span><span style="color: green;">&#91;</span><span style="color: green;">&#91;</span>Rule<span style="color: green;">&#93;</span><span style="color: green;">&#93;</span><span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: green;">&#91;</span>UV<span style="color: green;">&#93;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">IO</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></pre></div></div>

<p>Now, we don&#8217;t actually have to call <code>writeC</code> our selves <sup class='footnote'><a href='#fn-84-1' id='fnref-84-1'>1</a></sup>, but it does get called by <code>compile</code> from Language.Atom.Compile. The compile function now has this type signature:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">compile <span style="color: #339933; font-weight: bold;">::</span> Name <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">Maybe</span> AtomConfig <span style="color: #339933; font-weight: bold;">-&gt;</span> Atom <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">IO</span> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></pre></div></div>

<p>Other than the example in Language.Atom.Example, this is the only visible code that I changed.</p>
<p>Here&#8217;s how you use the <code>AtomConfig</code> type:</p>

<div class="wp_syntax"><div class="code"><pre class="haskell" style="font-family:monospace;">cType <span style="color: #339933; font-weight: bold;">::</span> Type <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #cccc00; font-weight: bold;">String</span>
cType t <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">case</span> t <span style="color: #06c; font-weight: bold;">of</span>
  <span style="color: #cccc00; font-weight: bold;">Bool</span>   <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint8_t&quot;</span>
  Int8   <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int8_t&quot;</span>
  Int16  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int16_t&quot;</span>
  Int32  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int32_t&quot;</span>
  Int64  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;int64_t&quot;</span>
  Word8  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint8_t&quot;</span>
  Word16 <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint16_t&quot;</span>
  Word32 <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint32_t&quot;</span>
  Word64 <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;uint64_t&quot;</span>
  <span style="color: #cccc00; font-weight: bold;">Float</span>  <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;float&quot;</span>
  <span style="color: #cccc00; font-weight: bold;">Double</span> <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="background-color: #3cb371;">&quot;double&quot;</span>
&nbsp;
cfg <span style="color: #339933; font-weight: bold;">=</span> AtomConfig <span style="color: green;">&#123;</span>
    cIncludes <span style="color: #339933; font-weight: bold;">=</span> Just <span style="color: green;">&#91;</span><span style="background-color: #3cb371;">&quot;blink.h&quot;</span><span style="color: green;">&#93;</span><span style="color: #339933; font-weight: bold;">,</span>
    cTyper    <span style="color: #339933; font-weight: bold;">=</span> Just cType
<span style="color: green;">&#125;</span></pre></div></div>

<p>First, we define a function that takes a <code>Type</code> and produces a string representing the C type. We build the config with an optional list of include files <sup class='footnote'><a href='#fn-84-2' id='fnref-84-2'>2</a></sup> and an optional typing function. If <code>Nothing</code> is passed to both fields, then Atom will not use any include files and will use the built in type converter.</p>
<p>In the next post, we&#8217;ll start building a simple program: blink an LED hooked up to some I/O pins on the Arduino.</p>
<p>I&#8217;ve posted a <a href="http://code.sw17ch.com/blog/atom/atom_0.0.2_sw17ch_1.diff">diff</a> of my changes to atom-0.0.2. Any criticisms are welcome.
<div class='footnotes'>
<div class='footnotedivider'></div>
<ol>
<li id='fn-84-1'>At least, I haven&#8217;t seen a reason to yet&#8211;perhaps this should not be exposed? <span class='footnotereverse'><a href='#fnref-84-1'>&#8617;</a></span></li>
<li id='fn-84-2'>These includes are the kinds that use quotes, not angle brackets. We&#8217;ll see <code>#include "blink.h"</code> rather than <code>#include &lt;blink.h></code>. <span class='footnotereverse'><a href='#fnref-84-2'>&#8617;</a></span></li>
</ol>
</div>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=84</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>My TODO List</title>
		<link>http://blog.sw17ch.com/wordpress/?p=79</link>
		<comments>http://blog.sw17ch.com/wordpress/?p=79#comments</comments>
		<pubDate>Mon, 23 Feb 2009 04:01:38 +0000</pubDate>
		<dc:creator>John Van Enk</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[portaudio]]></category>
		<category><![CDATA[Scurry]]></category>
		<category><![CDATA[todo]]></category>

		<guid isPermaLink="false">http://blog.sw17ch.com/wordpress/?p=79</guid>
		<description><![CDATA[I&#8217;m making this public so that I will be hounded if fail to complete these tasks or find some one to do these for me (hint hint): Write a Haskel FFI interface for libdnet. Write a Haskell FFI inteface for libgcrypt. Finish a GUI for Scurry. Start working on my portaudio FFI interface again. There, I [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m making this public so that I will be hounded if fail to complete these tasks or find some one to do these for me (hint hint):</p>
<ul>
<li>Write a Haskel FFI interface for <a href="http://libdnet.sourceforge.net/">libdnet</a>.</li>
<li>Write a Haskell FFI inteface for <a href="http://www.gnupg.org/documentation/manuals/gcrypt/">libgcrypt</a>.</li>
<li>Finish a GUI for <a href="http://code.google.com/p/scurry/">Scurry</a>.</li>
<li>Start working on my <a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/portaudio">portaudio</a> FFI interface again.</li>
</ul>
<p>There, I said it, and now it&#8217;s public. Some one hold me to this please!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sw17ch.com/wordpress/?feed=rss2&amp;p=79</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
