<?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>chris moos&#039;s blog &#187; haskell</title>
	<atom:link href="http://chrismoos.com/tag/haskell/feed/" rel="self" type="application/rss+xml" />
	<link>http://chrismoos.com</link>
	<description>coding my way through life</description>
	<lastBuildDate>Sun, 18 Sep 2011 19:48:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>Apple Push Notification Library for&#160;Haskell</title>
		<link>http://chrismoos.com/2009/07/13/apple-push-notification-library-for-haskell/</link>
		<comments>http://chrismoos.com/2009/07/13/apple-push-notification-library-for-haskell/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 20:40:29 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[apple]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[iphone]]></category>
		<category><![CDATA[push]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=421</guid>
		<description><![CDATA[I have been working with Apple&#8217;s Push Notification service recently and decided to make a library to send notifications with Haskell. It is very simple and has a few helpers to make notifications with an alert, sound, etc,. ApplePush Hackage ApplePush Documentation When using the library, you must use an SSL tunnel, because Haskell&#8217;s SSL [...]]]></description>
			<content:encoded><![CDATA[<p>I have been working with Apple&#8217;s Push Notification service recently and decided to make a library to send notifications with Haskell. It is very simple and has a few helpers to make notifications with an alert, sound, etc,. </p>
<p><img src="http://cdn.chrismoos.com/wp-content/uploads/2009/07/push.jpg" style="padding: 25px; width: 350px; float: right;"/></p>
<p><a href="http://hackage.haskell.org/package/ApplePush-0.1">ApplePush Hackage</a></p>
<p><a href="http://chrismoos.com/static/ApplePush/">ApplePush Documentation</a></p>
<p>When using the library, you must use an SSL tunnel, because Haskell&#8217;s SSL support is incomplete. I use stunnel4, which works great, and offloads the SSL processing as well. Here are some basic instructions on getting started with the library.</p>
<p><span id="more-421"></span></p>
<h3>Stunnel setup</h3>
<p>Download your certificate from Apple. If you are using a Mac, export the certificate (.cer) into a directory. Also, export your private key as a .p12 file. Stunnel needs the certificate/key in one file, in the following format:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #660033;">-----BEGIN</span> RSA PRIVATE KEY-----<br />
YOUR KEY<br />
<span style="color: #660033;">-----END</span> RSA PRIVATE KEY-----<br />
<span style="color: #660033;">-----BEGIN</span> CERTIFICATE-----<br />
YOUR CERTIFICATE<br />
<span style="color: #660033;">-----END</span> CERTIFICATE-----</div></td></tr></tbody></table></div>
<p>Run the following commands to convert and concatenate your certificate/private key.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">openssl x509 <span style="color: #660033;">-in</span> cert.cer <span style="color: #660033;">-inform</span> DER <span style="color: #660033;">-outform</span> PEM <span style="color: #660033;">-out</span> cert.pem<br />
openssl pkcs12 <span style="color: #660033;">-in</span> key.p12 <span style="color: #660033;">-out</span> key.pem <span style="color: #660033;">-nodes</span><br />
<span style="color: #c20cb9; font-weight: bold;">cat</span> key.pem cert.pem <span style="color: #000000; font-weight: bold;">&gt;</span> certs.pem</div></td></tr></tbody></table></div>
<p>Create a file called tun.conf, which will configure stunnel.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">client</span>=<span style="color: #c20cb9; font-weight: bold;">yes</span><br />
<span style="color: #007800;">debug</span>=<span style="color: #000000;">5</span><br />
<span style="color: #007800;">foreground</span>=no<br />
<span style="color: #007800;">pid</span>=tun.pid<br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span>service<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
<span style="color: #007800;">accept</span>=<span style="color: #000000;">2195</span><br />
<span style="color: #007800;">connect</span>=gateway.sandbox.push.apple.com:<span style="color: #000000;">2195</span><br />
<span style="color: #007800;">cert</span>=certs.pem</div></td></tr></tbody></table></div>
<p>This will bind stunnel to the local port 2195, and tunnel traffic via SSL to <em>gateway.sandbox.push.apple.com:2195</em>.</p>
<p>Next run the following command to start <em>stunnel</em>.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">stunnel tun.conf</div></td></tr></tbody></table></div>
<h3>ApplePush Haskell Library</h3>
<p>Let&#8217;s update our cabal packages, and then install.</p>
<div class="codecolorer-container sh blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br /></div></td><td><div class="sh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cabal update<br />
cabal <span style="color: #c20cb9; font-weight: bold;">install</span> ApplePush</div></td></tr></tbody></table></div>
<p>In addition to the library, an application, called <em>applepushtest</em>, is also installed so that you can test the library and your SSL tunnel setup. Let&#8217;s try it out. </p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">c10k:~ chris$ ~<span style="color: #000000; font-weight: bold;">/</span>.cabal<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>applepushtest <br />
Apple Push Test, Version <span style="color: #000000;">0.1</span><br />
usage: applepushtest device_token<span style="color: #7a0874; font-weight: bold;">&#40;</span>hex<span style="color: #7a0874; font-weight: bold;">&#41;</span></div></td></tr></tbody></table></div>
<p>You must pass a parameter, device_token, to the application. This tells the library which device to send the notification to. This token must be retrieved in your client application using <a href="http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW1">registerForRemoteNotificationTypes:</a>. Once you have your token, run the following command. </p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br /></div></td><td><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">c10k:~ chris$ ~<span style="color: #000000; font-weight: bold;">/</span>.cabal<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>applepushtest <span style="color: #7a0874; font-weight: bold;">&#40;</span>yourtoken<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
Device Token: <span style="color: #7a0874; font-weight: bold;">&#40;</span>yourtoken<span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
Message<span style="color: #000000; font-weight: bold;">&gt;</span> hey<br />
Message<span style="color: #000000; font-weight: bold;">&gt;</span> whats up?<br />
Message<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">test</span><span style="color: #000000; font-weight: bold;">!!</span><br />
Message<span style="color: #000000; font-weight: bold;">&gt;</span></div></td></tr></tbody></table></div>
<p>To use the library in your application, check out Main.hs for an example.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2009/07/13/apple-push-notification-library-for-haskell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Haskell AIM Client &#8211; a cool proof of&#160;concept</title>
		<link>http://chrismoos.com/2009/05/26/haskell-aim-client-a-cool-proof-of-concept/</link>
		<comments>http://chrismoos.com/2009/05/26/haskell-aim-client-a-cool-proof-of-concept/#comments</comments>
		<pubDate>Tue, 26 May 2009 18:29:21 +0000</pubDate>
		<dc:creator>Chris Moos</dc:creator>
				<category><![CDATA[Technology]]></category>
		<category><![CDATA[aim]]></category>
		<category><![CDATA[haskell]]></category>
		<category><![CDATA[oscar]]></category>

		<guid isPermaLink="false">http://chrismoos.com/?p=374</guid>
		<description><![CDATA[Haskell has been my favorite programming language in the past month, and for good reason. Its (purely) functional and has strong, static typing. The language feels more graceful to me, where design and function are key. It is a joy to program in and I would love to keep exploring it. On my path to [...]]]></description>
			<content:encoded><![CDATA[<p>Haskell has been my favorite programming language in the past month, and for good reason. Its (purely) functional and has strong, static typing. </p>
<p>The language feels more graceful to me, where design and function are key. It is a joy to program in and I would love to keep exploring it.</p>
<p><img src="http://www.moostrax.com/cmoos/RunningMan_AIM.gif" style="width: 300px;padding:10px;float:right;" /></p>
<p>On my path to learning a new language, I usually try to implement something to get some real-world experience. In this instance, I have chosen to implement an Open AIM client. AIM operates on the legacy TOC(text based) protocol, or the feature full <a href="http://dev.aol.com/aim/oscar/">OSCAR protocol</a>, which is what most AIM clients use. I decided that OSCAR would be more fun to do, especially with the <a href="http://dev.aol.com/aim/oscar/#SIGNON">three step login process</a>.</p>
<p>The client that I wrote is very simple &#8212; handles login to AIM and just sits there. It can get IM&#8217;s though. The bulk of the AIM client that I enjoyed writing was the protocol handlers, and implementing the login process.</p>
<p>It would be very easy to extend this client to be a bot, if you are looking for a practical use for it. For me, the learning experience is enough.</p>
<p><span id="more-374"></span></p>
<p>The main function is listed below.</p>
<div class="codecolorer-container haskell blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br />13<br />14<br /></div></td><td><div class="haskell codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">start<span style="color: #339933; font-weight: bold;">_</span>aim <span style="color: #339933; font-weight: bold;">=</span> <span style="color: #06c; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:putStrLn"><span style="font-weight: bold;">putStrLn</span></a> <span style="background-color: #3cb371;">&quot;Haskell AIM Client - OSCAR Protocol&quot;</span><br />
&nbsp; &nbsp; appKey <span style="color: #339933; font-weight: bold;">&lt;-</span> getAppKey<br />
&nbsp; &nbsp; screenName <span style="color: #339933; font-weight: bold;">&lt;-</span> getScreenName<br />
&nbsp; &nbsp; password <span style="color: #339933; font-weight: bold;">&lt;-</span> getPassword<br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">let</span> clientInfo <span style="color: #339933; font-weight: bold;">=</span> AIMClientInfo <span style="color: red;">1</span> <span style="background-color: #3cb371;">&quot;HaskellClient&quot;</span> appKey<br />
&nbsp; &nbsp; result <span style="color: #339933; font-weight: bold;">&lt;-</span> aim<span style="color: #339933; font-weight: bold;">_</span>open<span style="color: #339933; font-weight: bold;">_</span>auth clientInfo screenName password<br />
&nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">case</span> result <span style="color: #06c; font-weight: bold;">of</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Just info <span style="color: #339933; font-weight: bold;">-&gt;</span> <span style="color: #06c; font-weight: bold;">do</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; boss<span style="color: #339933; font-weight: bold;">_</span>result <span style="color: #339933; font-weight: bold;">&lt;-</span> aim<span style="color: #339933; font-weight: bold;">_</span>boss<span style="color: #339933; font-weight: bold;">_</span>session clientInfo info<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #06c; font-weight: bold;">case</span> boss<span style="color: #339933; font-weight: bold;">_</span>result <span style="color: #06c; font-weight: bold;">of</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Just si <span style="color: #339933; font-weight: bold;">-&gt;</span> aim<span style="color: #339933; font-weight: bold;">_</span>oscar<span style="color: #339933; font-weight: bold;">_</span>login si<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Nothing <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:putStrLn"><span style="font-weight: bold;">putStrLn</span></a> <span style="background-color: #3cb371;">&quot;Unable to authenticate with BOSS server.&quot;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; Nothing <span style="color: #339933; font-weight: bold;">-&gt;</span> <a href="http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:return"><span style="font-weight: bold;">return</span></a> <span style="color: green;">&#40;</span><span style="color: green;">&#41;</span></div></td></tr></tbody></table></div>
<p>If you want to try out this AIM client, you must have an <a href="http://developer.aim.com/manageKeys.jsp">Open AIM Developer key</a>.</p>
<p>The first step is to <a href="http://www.moostrax.com/cmoos/haim.tar.gz">download the source</a> and use cabal to configure, build, and install it.</p>
<div class="codecolorer-container sh blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br /></div></td><td><div class="sh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;"># wget http://www.moostrax.com/cmoos/haim.tar.gz</span><br />
<span style="color: #666666; font-style: italic;"># tar -xzf haim.tar.gz</span><br />
<span style="color: #666666; font-style: italic;"># cd haim</span><br />
<span style="color: #666666; font-style: italic;"># cabal configure &amp;&amp; cabal build &amp;&amp; cabal install</span></div></td></tr></tbody></table></div>
<p>And then run it.</p>
<div class="codecolorer-container sh blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br /></div></td><td><div class="sh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666;"># </span>~<span style="color: #000000; font-weight: bold;">/</span>.cabal<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span>haim</div></td></tr></tbody></table></div>
<p>The output will look something like this:</p>
<div class="codecolorer-container sh blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><table cellspacing="0" cellpadding="0"><tbody><tr><td style="padding:5px;text-align:center;color:#888888;background-color:#EEEEEE;border-right: 1px solid #9F9F9F;font: normal 12px/1.4em Monaco, Lucida Console, monospace;"><div>1<br />2<br />3<br />4<br />5<br />6<br />7<br />8<br />9<br />10<br />11<br />12<br /></div></td><td><div class="sh codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Haskell AIM Client - OSCAR Protocol<br />
An Open AIM Developer key is required: http:<span style="color: #000000; font-weight: bold;">//</span>developer.aim.com<span style="color: #000000; font-weight: bold;">/</span>manageKeys.jsp<br />
Open AIM Key<span style="color: #000000; font-weight: bold;">&gt;</span> <br />
AIM Screen Name<span style="color: #000000; font-weight: bold;">&gt;</span> <br />
AIM Password<span style="color: #000000; font-weight: bold;">&gt;</span> <br />
Connected to AIM server.<br />
Entered OSCAR client loop.<br />
Login accepted by OSCAR server. Setting up rights.<br />
Max Watchers: <span style="color: #000000;">2000</span><br />
Max Buddies: <span style="color: #000000;">1000</span><br />
Max Temp Buddies: <span style="color: #000000;">160</span><br />
Max Denies: <span style="color: #000000;">1000</span></div></td></tr></tbody></table></div>
<p>Like I said, the client is very simple, and just sits and waits. When you login you will see some information about your buddy list, and other AIM login data.</p>
]]></content:encoded>
			<wfw:commentRss>http://chrismoos.com/2009/05/26/haskell-aim-client-a-cool-proof-of-concept/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

