<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>All Posts</title>
        <link>http://blog.gregweber.info</link>
        <description><![CDATA[All posts from Greg Weber's Programming Blog]]></description>
        <atom:link href="http://blog.gregweber.info/rss/all.xml" rel="self"
                   type="application/rss+xml" />
        <lastBuildDate>Sat, 30 Jul 2011 00:00:00 UT</lastBuildDate>
        <item>
    <title>Announcing Yesod 0.9</title>
    <link>http://blog.gregweber.info/posts/2011-07-30-announcing-yesod-0.9</link>
    <description><![CDATA[<p>Lately I have put a lot of effort into imporving the web framework Yesod. We are very proud to <a href="http://www.yesodweb.com/blog/2011/08/announcing-yesod-0.9">announce a new release over on the Yesod blog</a>.</p>]]></description>
    <pubDate>Sat, 30 Jul 2011 00:00:00 UT</pubDate>
    <guid>http://blog.gregweber.info/posts/2011-07-30-announcing-yesod-0.9</guid>
</item>
<item>
    <title>Haskell Error Location</title>
    <link>http://blog.gregweber.info/posts/2011-07-23-hakell-error-location</link>
    <description><![CDATA[<p>One of the most annoying things about Haskell is a lack of any useful information on a crash. This isn’t as bad as it sounds because it actually is not hard to write a program that does not crash due to the excellent type safety. But sometimes I just want a quick and dirty hack to assert that my program is sane and I don’t care if it crashes. One case of this would be supporting code that is only executed for tests. Rather than having to check for an error return type, I might rather write a partial function that always returns a success type and will otherwise fail.</p>
<p>Template Haskell exposes a little known location data structure so that you can know exactly where the template haskell is being invoked, so my version of error that gives the file location looks about like this:</p>
<pre class="sourceCode"><code class="sourceCode haskell"><span class="ot">{-# LANGUAGE TemplateHaskell #-}</span><br /><span class="kw">import</span> <span class="dt">Language.Haskell.TH.Syntax</span><br /><br /><span class="ot">err </span><span class="ot">::</span> <span class="dt">String</span> <span class="ot">-&gt;</span> <span class="dt">Q</span> <span class="dt">Exp</span><br />err str <span class="fu">=</span> <span class="kw">do</span><br />    loc <span class="ot">&lt;-</span> qLocation<br />    <span class="kw">let</span> prefix <span class="fu">=</span> (location loc) <span class="fu">++</span> <span class="st">&quot; &quot;</span><br />    [<span class="fu">|</span><span class="fu">error</span> (prefix <span class="fu">++</span> str)<span class="fu">|</span>]<br />  <span class="kw">where</span><br />    location loc <span class="fu">=</span> (loc_package loc) <span class="fu">++</span> <span class="st">&quot;:&quot;</span> <span class="fu">++</span> (loc_module loc) <span class="fu">++</span> <span class="st">&quot; &quot;</span> <span class="fu">++</span><br />      (loc_filename loc) <span class="fu">++</span> <span class="st">&quot;:&quot;</span> <span class="fu">++</span> (line loc) <span class="fu">++</span> <span class="st">&quot;:&quot;</span> <span class="fu">++</span> (char loc)<br />    line <span class="fu">=</span> <span class="fu">show</span> <span class="fu">.</span> <span class="fu">fst</span> <span class="fu">.</span> loc_start<br />    char <span class="fu">=</span> <span class="fu">show</span> <span class="fu">.</span> <span class="fu">snd</span> <span class="fu">.</span> loc_start<br /><br /><span class="fu">&gt;</span> <span class="fu">$</span>(err <span class="st">&quot;OH NO!&quot;</span>)<br />main<span class="fu">:</span><span class="dt">Main</span> main<span class="fu">.</span>hs<span class="fu">:</span><span class="dv">16</span><span class="fu">:</span><span class="dv">1</span> <span class="dt">OH</span> <span class="dt">NO</span><span class="fu">!</span></code></pre>
<p>I put a module up on Hackage called <a href="">ErrorLocation</a>. It exposes the functions err (error), undef (undefined), and trc (Debug.Trace.trace). All of these behave the same as their normal counterpart but also spit out a location. I also included my favorite helper, debug, which is like trace but just show the value.</p>
<pre class="sourceCode"><code class="sourceCode haskell"><span class="ot">debug </span><span class="ot">::</span> <span class="kw">Show</span> a <span class="ot">=&gt;</span> a <span class="ot">-&gt;</span> a<br />debug x <span class="fu">=</span> trace (<span class="st">&quot;DEBUG: &quot;</span> <span class="fu">++</span> <span class="fu">show</span> x) x<br /><br /><span class="fu">&gt;</span> debug [<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>]<br /><span class="dt">DEBUG</span><span class="fu">:</span> [<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>]<br />[<span class="dv">1</span>,<span class="dv">2</span>,<span class="dv">3</span>]</code></pre>
<p>I am going to need a little help for the Template Haskell version of that one, but then I will include it also.</p>]]></description>
    <pubDate>Sat, 23 Jul 2011 00:00:00 UT</pubDate>
    <guid>http://blog.gregweber.info/posts/2011-07-23-hakell-error-location</guid>
</item>
<item>
    <title>Haskell on Heroku</title>
    <link>http://blog.gregweber.info/posts/2011-07-22-haskell-on-heroku</link>
    <description><![CDATA[<p>I blog about Ruby and Haskell. Its great when there is some kind of synergy between the two. Heroku is a great deployment environment formally just for Ruby apps. I wrote an article about <a href="http://www.yesodweb.com/blog/2011/07/haskell-on-heroku">deploying a Yesod application to Heroku</a>.</p>]]></description>
    <pubDate>Fri, 22 Jul 2011 00:00:00 UT</pubDate>
    <guid>http://blog.gregweber.info/posts/2011-07-22-haskell-on-heroku</guid>
</item>

    </channel> 
</rss>
