<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Reichert Brothers Software Development</title>
    <link href="http://reichertbrothers.com/atom.xml" rel="self" />
    <link href="http://reichertbrothers.com" />
    <id>http://reichertbrothers.com/atom.xml</id>
    <author>
        <name>Christopher Reichert</name>
        <email>christopher@reichertbrothers.com</email>
    </author>
    <updated>2014-06-23T00:00:00Z</updated>
    <entry>
    <title>Yesod and Angular JS</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-06-23-yesod-angular-integration.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-06-23-yesod-angular-integration.html</id>
    <published>2014-06-23T00:00:00Z</published>
    <updated>2014-06-23T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on June 23, 2014
    
        by Christopher Reichert
    
</div>

<div style="text-align:center; margin-right: 20px; margin-bottom: 20px" markdown="1">
<p><img src="/images/yesod.png" alt="Yesod Web Framework"
       style="height:200px; float: left; display: inline-block; margin-right: 20px"/></p>
</div>
<p>Recently, while working on a <a href="http://www.yesodweb.com/">Yesod</a> site I wanted to integrate <a href="https://angularjs.org/">Angular JS</a> to spice up the design and add dynamic content.</p>
<p>Researching Angular js and Yesod integration via search engines doesn’t yield many helpful results. Michael Snoyman has an example from 2012 (<a href="http://www.yesodweb.com/blog/2012/10/yesod-fay-js" class="uri">http://www.yesodweb.com/blog/2012/10/yesod-fay-js</a>) with a module named <code>Yesod.Angular</code> provided for integrating Angular with a Haskell/Yesod backend. The problem is most of the code in the module was written against an older version of Yesod, and thus, does not compile with current versions.</p>
<p>I have proposed a <a href="https://github.com/snoyberg/yesod-js/pull/2">pull request</a> to update the example to work with Yesod 1.2, so those who stumble upon it are not confused or blocked. The pull request was merged and should be in the <a href="https://github.com/snoyberg/yesod-js">yesod-js</a> repository now.</p>
<!--more-->
<p>If you want to integrate the <a href="https://github.com/creichert/yesod-js/blob/master/yesod-angular/Yesod/Angular.hs">Yesod.Angular</a> module into your project you will need to include it directly in your code. I am working to make this module usable as a library so feel free to comment with any suggestions.</p>
<p>The complete code can be found on <a href="https://github.com/creichert/yesod-js/commit/6dd9989c4232dabcd7eae977a2d3722a34605064">Github</a></p>
<p>Happy Hacking!</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>HsQML StocQt - Stock Market Visualization in Haskell and Qt Quick</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-06-06-hsqmlstocqt-haskell-qml-data-visualization.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-06-06-hsqmlstocqt-haskell-qml-data-visualization.html</id>
    <published>2014-06-06T00:00:00Z</published>
    <updated>2014-06-06T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on June  6, 2014
    
        by Christopher Reichert
    
</div>

<p><br/> Recently, I have been working on porting some Qt Quick demo applications to Haskell and <a href="http://www.gekkou.co.uk/software/hsqml/">HsQML</a>. The idea is to develop more non-trivial examples to showcase the power of HsQML. The outcome has been quite impressive and HsQML has been a pleasure to work with, as usual.</p>
<p>Here are some images of the ported StocQt app:</p>
<p><img alt="HsQMLStocQt" src="/images/hsqmlstocqt.png" height="300" /> <img alt="HsQMLStocQt" src="/images/hsqmlstocqt2.png" height="300" /> <img alt="HsQMLStocQt" src="/images/hsqmlstocqt3.png" height="300" /></p>
<!--more-->
<p>The problem is that only general trends are legible and it’s difficult to see the exact figures. This works very similar to googles own high level finance viewer: <a href="https://www.google.com/finance?cid=22144" class="uri">https://www.google.com/finance?cid=22144</a>.</p>
<p>I am still working on updating this example new styles which should increase readably: <a href="http://qt-project.org/doc/qt-5/qtquick-demos-stocqt-example.html" class="uri">http://qt-project.org/doc/qt-5/qtquick-demos-stocqt-example.html</a></p>
<p>Of course, Haskell doesn’t have much to do with the look and feel. Styling is mostly handled on the QML side. The Haskell code is managing all QML properties and also providing functions for manipulating the data. The code is currently a bit littered with <a href="http://www.haskell.org/ghc/docs/latest/html/libraries/base/Control-Concurrent-MVar.html">MVar’s</a> but I am working on some patterns which might help mitigate the need for them to be so ubiquitous.</p>
<p>The working code can be found at: <a href="https://github.com/creichert/hsqmlstocqt" class="uri">https://github.com/creichert/hsqmlstocqt</a></p>
<h1 id="inspecting-hsqml-stocqt-via-gammaray">Inspecting HsQML StocQt via GammaRay</h1>
<p>Out of curiousity, I decided to use <a href="https://github.com/KDAB/GammaRay">GammaRay</a> on the app. Gammaray is a tool for inspecting a Qt application and also allows you to manipulat the program to some extent. I was not surprised to see it work right away. Note the <code>HsQMLManagerApp</code> and <code>HsQMLEngine</code> types which are core to the functionality of HsQML.</p>
<p><img alt="HsQMLStocQt" src="/images/grhsqmlstocqt.png" height="500" /></p>
<p>I am still unsure how much GammaRay can tell us about the Haskell data. However, it does give us a great tool to check the functionality at the Qt Quick level. I will be reporting back on using GammaRay to manipulate our data and identify issues in Qt Quick.</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>Houston Haskell - Installing GHC and Working With Cabal</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-05-02-hhug-ghc-and-cabal.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-05-02-hhug-ghc-and-cabal.html</id>
    <published>2014-05-02T00:00:00Z</published>
    <updated>2014-05-02T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on May  2, 2014
    
        by Christopher Reichert
    
</div>

<div style="text-align:center" markdown="1">
<p><img src="/images/houston.png" alt="Houston Haskell Users Group" style="height: 250px;"/></p>
</div>
<p>The first official meeting for the Houston Haskell Users Group was a success! There seems to be many Haskellers in the Houston area who are hungry to learn more.</p>
<!--more-->
<p>We talked about installing GHC and Cabal, working with Cabal sandboxes, resolving dependencies and errors that arise from Cabal use from time to time, and much more.</p>
<p>The slides and code samples can be found here: <a href="/talks/GHCandCabal/index.html">GHCandCabal.slides</a></p>
<p>If you are in the Houston area or just passing through and would like to give a talk or just join us the email me: christopher at reichert brothers dot com.</p>
<p>Happy Hacking!</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>Exploring QML In Haskell</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-04-30-exploring-hsqml.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-04-30-exploring-hsqml.html</id>
    <published>2014-04-30T00:00:00Z</published>
    <updated>2014-04-30T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on April 30, 2014
    
        by Christopher Reichert
    
</div>

<div style="text-align:center" markdown="1">
<p><img src="/images/haskell_logo2.png" alt="Haskell logo"
       style="height:200px; float: left; display: inline-block"/></p>
</div>
<div style="text-align:center" markdown="1">
<p><img src="/images/multiply.png" alt="Plus symbol."
       style="height:100px; float: left; display: inline-block; padding-left: 40px; margin: 40px 40px"/></p>
</div>
<div style="text-align:center" markdown="1">
<p><img src="/images/qt-logo.png" alt="Qt logo"
       style="height:200px; display: inline-block"/></p>
</div>
<p>I have recently been experimenting with the Haskell QML binding <a href="http://hackage.haskell.org/package/hsqml">HsQML</a>. I am a big fan of QML and it’s portability. It’s a very flexible language for user interface development and it makes for a powerful combination with Haskell.</p>
<p>Recently, I wrote about integrating <a href="http://reichertbrothers.com/blog/posts/2014-04-15-qml-haskell-integration-with-fay.html">QML code and Haskell using Fay</a>.</p>
<p>HsQML, however, is a more direct way of integrating QML and Haskell. The HsQML approach has the value of the Haskell runtime and garbage collector, among other things (though, Fay may compile the garbage collector, not sure).</p>
<p>This post describes working with HsQML &lt; 0.3.</p>
<!--more-->
<div class="warning">
<p>As of HsQML 0.3 many of the issues I describe in this post are fixed. I will have a follow-up post soon talking about HsQML 0.3!</p>
</div>
<p>HsQML is a binding to the QML engine from Haskell. The library is still fairly young but it is extremely useful and can definitely get the job done. The current HsQML packages in Hackage only support Qt4/QtDeclarative but there is Qt5/QtQml support in the <a href="http://hub.darcs.net/komadori/HsQML/">HsQML Darcs Repository</a>. I have tested HsQML with Qt5 and everything seems to be working very well.</p>
<p>I have begun implementing a <a href="https://github.com/prof7bit/TorChat">TorChat</a> client in Haskell using HsQML. You can find the code on my <a href="https://github.com/creichert/hstorchat">Github</a>. Contributions welcome! HSTorChat uses many basic features of HsQML and can definitely be used as an example for developing more complex user interfaces in QML.</p>
<p>TorChat is a simple messenger application that is built on top of Tor’s hidden services. When an HSTorChat client is talking to a buddy, outgoing messages are gauranteed to be sent to the correct onion address.</p>
<blockquote>
<p>Everyone – including the introduction points, the distributed hash table directory, and of course the clients – can verify that they are talking to the right hidden service</p>
<p>– https://www.torproject.org/docs/hidden-services.html.en</p>
</blockquote>
<p><br/></p>
<h1 id="hstorchat">HSTorChat</h1>
<p><br/></p>
<h4 id="state">State</h4>
<p>Managing state in a Haskell GUI application is not always trivial. I was largely unable to use Haskell data structures as QML models. I initially attempted to define read-write properties which could be updated from QML. However, I found that with lack of support for property signals I was unable to get QML to always update the views to reflect the state. I was able to work through these issues more easily in HsQML 0.3.</p>
<p>Because each buddy is managed on a differed thread, there must be some way to coordinate changes with the ui. The buddy list serves as the point of communication between threads and uses an <a href="https://hackage.haskell.org/package/base-4.0.0.0/docs/Control-Concurrent-MVar.html">MVar</a>. When a new buddy authenticates, the corresponding onion address is added to an MVar’d buddy list using <code>takeMVar</code> and <code>putMVar</code> (or <code>withMVar</code> to combine the operations):</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    buds&#39; <span class="ot">&lt;-</span> takeMVar <span class="fu">$</span> _buddies ui&#39;
    putMVar (_buddies ui&#39;) (b<span class="fu">:</span>buds&#39;)</code></pre></div>
<p><strong><em>(This should be done using withMVar)</em></strong></p>
<p>Since each buddy is managed in it’s own thread, the MVar enables syncing messages from the ui to the corresponding buddy.</p>
<h4 id="signals">Signals</h4>
<p>When a new message is received a signal is sent from Haskell to QML.</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    m <span class="ot">&lt;-</span> newObject <span class="fu">$</span> <span class="dt">Msg</span> (T.unpack msg) onion
    fireSignal (<span class="dt">Tagged</span><span class="ot"> ui ::</span> <span class="dt">Tagged</span> <span class="dt">MsgReady</span> (<span class="dt">ObjRef</span> <span class="dt">UI</span>)) m</code></pre></div>
<p><code>fireSignal</code> is called from the thread managing the Buddy. The HsQML documentation has been updated to reflect that the function safe to call from any thread:</p>
<p>http://hub.darcs.net/komadori/HsQML/patch/20140507214126-4d2ae</p>
<h4 id="calling-haskell-functions-from-qml">Calling Haskell functions from QML</h4>
<p>Calling Haskell functions from QML is quite simple. In GUI.hs, <code>sendMsg</code> defines a function on the main context object which takes three parameters:</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"> <span class="kw">instance</span> <span class="dt">Object</span> <span class="dt">UI</span> <span class="kw">where</span>
      classDef <span class="fu">=</span> defClass [
            , defMethod <span class="st">&quot;sendMsg&quot;</span> sendMsg
            <span class="fu">...</span>
            ]
    
<span class="ot">    sendMsg ::</span> <span class="dt">ObjRef</span> <span class="dt">UI</span> <span class="ot">-&gt;</span> <span class="dt">T.Text</span> <span class="ot">-&gt;</span> <span class="dt">T.Text</span> <span class="ot">-&gt;</span> <span class="dt">IO</span> ()
    sendMsg ui onion msg <span class="fu">=</span> <span class="kw">do</span>
        <span class="kw">let</span> ui&#39; <span class="fu">=</span> fromObjRef ui
        buds <span class="ot">&lt;-</span> readMVar <span class="fu">$</span> _buddies ui&#39;
        sendMsgTo buds
      <span class="kw">where</span>
        sendMsgTo []   <span class="fu">=</span> putStrLn <span class="st">&quot;Unable to send msg: no buddies.&quot;</span>
        sendMsgTo buds <span class="fu">=</span> <span class="kw">do</span>
            <span class="co">-- Filter proper buddy from list.</span>
            <span class="kw">let</span> buddy <span class="fu">=</span> head <span class="fu">$</span> filter (λb <span class="ot">-&gt;</span> _addy b <span class="fu">==</span> T.unpack onion) buds
            hPutStrLn (_out_conn buddy) <span class="fu">$</span> lowercase <span class="fu">$</span> filter (<span class="fu">/=</span> <span class="ch">&#39;&quot;&#39;</span>) <span class="fu">$</span> show <span class="fu">$</span> <span class="dt">Message</span> msg
            return ()</code></pre></div>
<p><code>sendMsg</code> takes a reference to the UI object, a buddy name, and a message.</p>
<p>I admit, It would be better to experiment with constructing and passing a complete Msg type from QML instead of the onion and msg individually. The function definition could be more readable.</p>
<p>If you happen to peruse the code, you might notice there is also some discrepency between the ProtocolMsg Message and Msg type. I hope to combine the two in the next few revisions of HSTorChat.</p>
<p>Here is an example call to <code>sendMsg</code> in the <code>onAccepted</code> slot of a QML <a href="http://qt-project.org/doc/qt-4.8/qml-textinput.html">TextInput</a> component.</p>
<div class="sourceCode"><pre class="sourceCode javascript"><code class="sourceCode javascript">    onAccepted<span class="op">:</span> <span class="op">{</span> <span class="at">sendMsg</span>(<span class="st">&quot;buddyname&quot;</span><span class="op">,</span> <span class="st">&quot;buddyonion&quot;</span>) <span class="op">}</span></code></pre></div>
<h4 id="modelview">Model/View</h4>
<p>There is no straight forward way to implement data models for QML in Haskell that I am aware of. It would be nice to support actual <code>ListModel</code> declarations some way from within Haskell.</p>
<p>Update (5/6/2014): As of HsQML 0.3 I have had success using Haskell Lists as QML data models. See here for details <a href="https://github.com/creichert/hstorchat/commit/f3175e939fa5c10735e5fcdeec02a9383fa31d74" class="uri">https://github.com/creichert/hstorchat/commit/f3175e939fa5c10735e5fcdeec02a9383fa31d74</a></p>
<h4 id="error-reporting">Error reporting</h4>
<p>One thing that is very difficult is getting the output of errors in the event of a QML crash or error creating a component. Most of the time the failure is silent. I have not yet found a way to work around this besides testing the qml file separately with <code>qmlscene</code>.</p>
<p>Update: HsQML 0.3, however, has had fantastic error reporting.</p>
<h1 id="side-note">Side-Note</h1>
<p><a href="https://hackage.haskell.org/package/attoparsec">Attoparsec</a> and <a href="https://hackage.haskell.org/package/parsec">Parsec</a> are extremely cool parser combinator libraries for Haskell.</p>
<p>Anytime HSTorChat receives a new data packet on it’s input connection it attempts to apply a series of parser combinators which basically turn the message into the type of <code>ProtocolMsg</code> the data represents.</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    <span class="kw">data</span> <span class="dt">ProtocolMsg</span> <span class="fu">=</span> <span class="dt">Ping</span> <span class="fu">|</span> <span class="dt">Pong</span> <span class="fu">...</span>

<span class="ot">    parseResponse ::</span> <span class="dt">Parser</span> <span class="dt">ProtocolMsg</span> 
    parseResponse <span class="fu">=</span>  try parsePing
                 <span class="fu">&lt;|&gt;</span> try parsePong
                 <span class="fu">&lt;|&gt;</span> try parseVersion
                 <span class="fu">&lt;|&gt;</span> try parseClient
                 <span class="fu">&lt;|&gt;</span> try parseStatus
                 <span class="fu">&lt;|&gt;</span> try parseAddMe
                 <span class="fu">&lt;|&gt;</span> try parseDelayedMsg
                 <span class="fu">&lt;|&gt;</span> parseMsg</code></pre></div>
<p>Check out the definition of the ProtocolMsg <a href="https://github.com/creichert/hstorchat/blob/master/src/Network/HSTorChat/Protocol.hs#L56">here</a>.</p>
<p>Check out the definition of the combinators <a href="https://github.com/creichert/hstorchat/blob/master/src/Network/HSTorChat/Protocol.hs#L119">here</a>.</p>
<h1 id="coming-soon">Coming Soon</h1>
<p>HSTorchat in it’s current state accomplishes quite a lot. My next goal is to make HSTorChat into a full fledged chat client and port it to the Raspberry Pi.</p>
<p>I will also be experimenting with using Fay to generate JavaScript library code in an HsQML application. More to come!</p>
<p>Happy Hacking!</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>QML integration with Fay and Haskell</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-04-15-qml-haskell-integration-with-fay.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-04-15-qml-haskell-integration-with-fay.html</id>
    <published>2014-04-15T00:00:00Z</published>
    <updated>2014-04-15T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on April 15, 2014
    
        by Christopher Reichert
    
</div>

<div style="text-align:center" markdown="1">
<p><img src="/images/qt-logo.png" alt="Qt logo"
       style="height:200px; float: left; display: inline-block"/></p>
</div>
<div style="text-align:center" markdown="1">
<p><img src="/images/plus.png" alt="Plus symbol."
       style="height:100px; float: left; display: inline-block; padding-left: 40px; margin: 40px 40px"/></p>
</div>
<div style="text-align:center" markdown="1">
<p><img src="/images/haskell_logo2.png" alt="Haskell logo"
       style="height:200px; display: inline-block"/></p>
</div>
<p>If you are reading this, you are probably more or less aware of the <a href="http://www.haskell.org/haskellwiki/The_JavaScript_Problem">JavaScript Problem</a>. Like many, I frequently work with JavaScript. There is no avoiding JavaScript on the web and many corners of the software development industry.</p>
<p>My most recent JavaScript endeavor has been in the world of <a href="https://qt-project.org/wiki/Qt_5.0">Qt5</a> and <a href="http://qt-project.org/doc/qt-5/qtqml-index.html">QML</a>. QML is a solid toolkit for writing fluid and cross-platform user interfaces.</p>
<p>Recently, while experimenting with QML, I had a revelation. What if it was possible to generate QML code from Haskell using Fay. Eureka!</p>
<!--more-->
<p>Luckily, <a href="https://github.com/faylang/fay/wiki">Fay</a> is up for the job. Fay is a Haskell to Javascript compiler which supports a proper subset of the Haskell language. Fay has several distinct advantageous:</p>
<blockquote>
<ul>
<li>Statically typed</li>
<li>Lazy</li>
<li>Pure by default</li>
<li>Compiles to JavaScript</li>
<li>Has fundamental data types (Double, String, etc.) based upon what JS can support, and compound data types (ADTs and GADTs)</li>
<li>Outputs minifier-aware code for small compressed size</li>
<li>Has a trivial foreign function interface to JavaScript</li>
<li>Supports cabal installation of Fay packages</li>
<li>Can automatically transcode values to/from JSON using the FFI</li>
<li>Provides an API to transcode on the server side as well</li>
<li>Lets you call Fay code from JavaScript</li>
<li>Has the Fay monad for side effects (think of it like IO)</li>
</ul>
<p>– Fay Wiki</p>
</blockquote>
<p>This post will cover how to integrate a JavaScript library generated using Fay into a QML application. The library will be developed purely in Haskell while the UI code will be written in QML.</p>
<p>QML, while a subset of JavaScript, is essentially it’s own language. Fay does not understand QML and therefore cannot compile it to JavaScript yet.</p>
<p>My goal is to, first, get the JS library integration functioning. After that, the issue of getting Fay to compile QML Forms written in Haskell can be evaluated and potentially implemented.</p>
<p>The most up-to-date version of the <code>qmlfay</code> example source is on my <a href="https://github.com/creichert/qmlfay">Github</a>. I would like to get this unique example into the Fay repository if anyone else finds it useful.</p>
<h1 id="interfacing-a-haskell-library-with-qml-using-fay">Interfacing a Haskell Library With QML Using Fay</h1>
<p>The first objective is to pass <a href="http://qt-project.org/doc/qt-4.8/qml-qtobject.html">QtObjects</a>, created in QML, to a Fay JavaScript library. In the library, properties should be read from the QtObject and the data can be processed accordingly.</p>
<p>Make sure <code>fay</code> and <code>fay-base</code> are installed.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">cabal</span> install fay fay-base</code></pre></div>
<h5 id="haskell">Haskell</h5>
<p>Let’s start with the fun part. The Haskell module is named <code>Library</code> and exports a function named <code>qObjectName</code>. This function should return the objectName property of a QML <a href="http://qt-project.org/doc/qt-4.8/qml-qtobject.html">QtObject</a>.</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    <span class="kw">module</span> <span class="dt">Library</span> (qObjectName) <span class="kw">where</span></code></pre></div>
<p>The data type QObject is defined to represent our QML component (which is based on the QtObject element). Unfortunately, I have not yet found a way to generate this record based on the actual C++ QObject type properties. Fortunately, we only need fields for each property used. As far as I can tell, Fay matches the record entry with the JavaScript object’s property when applying this type.</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    <span class="kw">data</span> <span class="dt">QObject</span> <span class="fu">=</span> <span class="dt">QObject</span> {<span class="ot"> objectName ::</span> <span class="dt">String</span> }</code></pre></div>
<p>The function <code>qObjectName</code> takes a QObject parameter and returns the objectName. <code>undefined</code> will be returned if the <code>objectName</code> property doesn’t exist.</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell"><span class="ot">    qObjectName ::</span> <span class="dt">QObject</span> <span class="ot">-&gt;</span> <span class="dt">String</span>
    qObjectName qo <span class="fu">=</span> objectName qo</code></pre></div>
<p>Next, some boilerplate is necessary to initialize the QML application.</p>
<h2 id="boilerplate">Boilerplate</h2>
<p>First, we need a main.cpp file to run the application. While it is technically possible to run the app using <code>qmlscene</code>, I wanted to show an example with qmake so it can be more easily adapted to existing qmake build systems.</p>
<h5 id="main.cpp">Main.cpp</h5>
<div class="sourceCode"><pre class="sourceCode cpp"><code class="sourceCode cpp">    <span class="ot">#include &lt;QGuiApplication&gt;</span>
    <span class="ot">#include &lt;QQuickView&gt;</span>
    <span class="ot">#include &lt;QUrl&gt;</span>

    <span class="dt">int</span> main(<span class="dt">int</span> argc, <span class="dt">char</span>** argv) {
    
        QGuiApplication a(argc, argv);
    
        QQuickView view;
        view.setSource(<span class="ot">QUrl</span>(<span class="st">&quot;./Main.qml&quot;</span>));
        view.show();
    
        <span class="kw">return</span> a.exec();
    }</code></pre></div>
<p>The <code>QQuickView</code>’s source is set to <code>Main.qml</code> which is our QML entry point.</p>
<h5 id="main.qml">Main.qml</h5>
<p><code>Main.qml</code> starts off with imports. Our Fay generated JavaScript library, <code>Library.js</code>, is a qualified import named <code>Library</code>.</p>
<div class="sourceCode"><pre class="sourceCode javascript"><code class="sourceCode javascript"><span class="im">import</span> QtQuick <span class="fl">2.0</span> 
<span class="im">import</span> <span class="st">&quot;Library.js&quot;</span> <span class="im">as</span> Library</code></pre></div>
<p>Next, there is a <code>Rectangle</code> element. The <code>objectName</code> property, which will be accessed from <code>Library.js</code>, is set to <code>&quot;MyObject&quot;</code>.</p>
<p>We set the component <code>id</code> to <code>page</code> for reference.</p>
<div class="sourceCode"><pre class="sourceCode javascript"><code class="sourceCode javascript">Rectangle <span class="op">{</span>
    <span class="dt">id</span><span class="op">:</span> page
    <span class="dt">width</span><span class="op">:</span> <span class="dv">100</span><span class="op">;</span> <span class="dt">height</span><span class="op">:</span> <span class="dv">100</span> 
    <span class="dt">objectName</span><span class="op">:</span> <span class="st">&quot;MyObject&quot;</span>

    <span class="va">Component</span>.<span class="at">onCompleted</span><span class="op">:</span> <span class="op">{</span></code></pre></div>
<p>After a reference to the <code>Library</code> object is retrieved, it’s possible to run <code>L.objectName(page)</code>. Note that the id is being passed to the <code>qObjectName</code> function. The id is reference to the JavaScript object <code>page</code>.</p>
<div class="sourceCode"><pre class="sourceCode javascript"><code class="sourceCode javascript">        <span class="kw">var</span> L <span class="op">=</span> <span class="va">Library</span>.<span class="va">Strict</span>.<span class="at">Library</span><span class="op">;</span> <span class="co">// Pass --strict to fay compiler.</span>
        <span class="va">console</span>.<span class="at">log</span>(<span class="va">L</span>.<span class="at">qObjectName</span>(page))
    }   
}</code></pre></div>
<h5 id="qmlfay.pro">qmlfay.pro</h5>
<p>The qmake project file defines how the project should be built. <code>qmake</code> offers macros to extend the build with extra compilers. This should work perfectly for the Fay compiler build rules as their compilation is independent of the C++ sources.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">TEMPLATE</span> = app 
    <span class="kw">TARGET</span> = qmlfay
    <span class="kw">INCLUDEPATH</span> += .
    
    <span class="kw">QT</span> += gui quick
    <span class="kw">CONFIG</span> += target_predeps
    
    <span class="kw">SOURCES</span> += main.cpp
    <span class="kw">FAY_SOURCES</span> += Library.hs
    
    <span class="kw">fay.name</span> = fay compiling
    <span class="kw">fay.input</span> = FAY_SOURCES
    <span class="kw">fay.output</span> = <span class="ot">${QMAKE_FILE_IN_PATH}</span>/<span class="ot">${QMAKE_FILE_BASE}</span>.js</code></pre></div>
<p>Now the actual compile command is defined. Note the <code>--strict</code> flag.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">fay.commands</span> = fay <span class="ot">${QMAKE_FILE_NAME}</span> -p --strict <span class="ot">${QMAKE_FILE_BASE}</span>
    <span class="kw">fay.variable_out</span> = PRE_TARGETDEPS
    <span class="kw">QMAKE_EXTRA_COMPILERS</span> += fay </code></pre></div>
<h2 id="compile-and-run">Compile and Run</h2>
<p>Now compile and run the application.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">qmake-qt5</span> .
    <span class="kw">make</span>
    <span class="kw">./qmlfay</span></code></pre></div>
<h2 id="issues">Issues</h2>
<h5 id="expected-token-identifier-error">Expected token <code>identifier</code> error:</h5>
<p>You might run into the following error importing the JavaScript sources from QML:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    $ <span class="kw">./qmlfay</span> 
    <span class="kw">file</span>:///.../dev/qmlfay/Main.qml:3:1: Script file:///.../dev/qmlfay/Library.js unavailable 
         <span class="kw">import</span> <span class="st">&quot;Library.js&quot;</span> as Library 
         ^
    <span class="kw">file</span>:///.../dev/qmlfay/Library.js:2230:17: Expected token <span class="kw">`identifier</span><span class="st">&#39; </span>
<span class="st">                     var as = $tmp1.cdr;</span></code></pre></div>
<p>The workaround, for the time being, is to comment out the following functions from the generated javascript <code>Library.js</code>: <code>zipWith</code>,<code>zipWith3</code>,<code>zip</code>,<code>zip3</code>. This also means these functions are unusable for now.</p>
<h2 id="conclusions">Conclusions</h2>
<p>My goal is to bring a usable QtQuick experience to Haskell through the use of Fay. Once I have developed tighter library integration I plan to attempt to write a pass in the Fay compiler to handle pure qml.</p>
<p>I’m not unambiguously certain that all of these things are possible but this is an itch I must scratch.</p>
<p>Happy Hacking!</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>GHC Hacking</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-04-11-ghc-hacking.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-04-11-ghc-hacking.html</id>
    <published>2014-04-11T00:00:00Z</published>
    <updated>2014-04-11T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on April 11, 2014
    
        by Christopher Reichert
    
</div>

<div style="text-align:center" markdown="1">
<p><img src="/images/haskell_logo2.png" alt="Haskell Lambda" style="height: 250px;"/></p>
</div>
<p>If you haven’t figured it out already, I am a <a href="http://haskell.org/">Haskell</a> fanatic. Haskell is a fantastic language that has continuously driven me to explore new programming concepts and improve my own skill. Quite naturally, I am intrigued by <a href="">GHC – The Glasgow Haskell Compiler</a>. GHC is an open-source native code compiler for Haskell. GHC is written in Haskell with the majority of the runtime system written in C and C-- <a href="#0">[0]</a>.</p>
<p>This post describes how to:</p>
<ul>
<li>Check out and build the ghc source.</li>
<li>Add libraries to your inplace ghc instance.</li>
<li>Make a trivial change to GHCi.</li>
</ul>
<!--more-->
<p>Some of the highlights of the GHC compiler are described on <a href="http://haskell.org/ghc">haskell.org/ghc</a>:</p>
<blockquote>
<ul>
<li><p>GHC supports the entire Haskell 2010 language plus a wide variety of extensions.</p></li>
<li><p>GHC has particularly good support for concurrency and parallelism, including support for Software Transactional Memory (STM).</p></li>
<li><p>GHC generates fast code, particularly for concurrent programs. Take a look at GHC’s performance on The Computer Language Benchmarks Game.</p></li>
<li><p>GHC works on several platforms including Windows, Mac, Linux, most varieties of Unix, and several different processor architectures. There are detailed instructions for porting GHC to a new platform.</p></li>
<li><p>GHC has extensive optimisation capabilities, including inter-module optimisation.</p></li>
<li><p>GHC compiles Haskell code either directly to native code or using LLVM as a back-end. GHC can also generate C code as an intermediate target for porting to new platforms. The interactive environment compiles Haskell to bytecode, and supports execution of mixed bytecode/compiled programs.</p></li>
<li><p>Profiling is supported, both by time/allocation and various kinds of heap profiling.</p></li>
<li><p>GHC comes with several libraries, and thousands more are available on Hackage.</p></li>
</ul>
</blockquote>
<p>That’s a lot of great reasons to give the compiler a closer look. Before we get started, there are tons of resources to be found on the <a href="http://www.haskell.org/ghc/">GHC wiki</a> and even on the <a href="https://github.com/ghc/ghc">GHC github</a>.</p>
<h2 id="compiling-ghc">Compiling GHC</h2>
<p>Compiling GHC is actually fairly straightforward.</p>
<ol style="list-style-type: decimal">
<li>Get the code:</li>
</ol>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">git</span> clone git@github.com:ghc/ghc.git</code></pre></div>
<ol start="2" style="list-style-type: decimal">
<li>Sync the repository:</li>
</ol>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">cd</span> ghc
    <span class="kw">./sync-all</span> get
    <span class="kw">perl</span> boot</code></pre></div>
<ol start="3" style="list-style-type: decimal">
<li>Configure and build:</li>
</ol>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">./configure</span>
    <span class="kw">make</span> -j4</code></pre></div>
<p>This will take about an hour. If all is succesful you should have your shiny new GHC compiler in <code>./inplace/bin/ghc-stage2</code>.</p>
<h2 id="adding-extra-package-to-inplace-ghc.">Adding Extra Package to inplace GHC.</h2>
<p>Assuming you have a somewhat recent version of <code>cabal</code> installed, you can add extra packages to your inplace GHC using:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">cabal</span> install --with-compiler=/path/to/ghc/inplace/bin/ghc-stage2 <span class="kw">&lt;</span>package<span class="kw">&gt;</span></code></pre></div>
<p>You should then be able to list packages using <code>ghc-pkg</code>:</p>
<pre><code>    ./inplace/bin/ghc-pkg list</code></pre>
<h2 id="making-changes-to-ghc">Making changes to GHC</h2>
<p>The goal is to hack on GHC so let’s make a change. As a trivial example, I will change the banner text for GHCi.</p>
<p>First, open <code>GHC/InteractiveUI.hs</code>.</p>
<p>On line 128 we see the function for showing the GHCi welcome msg.</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    <span class="dt">GHCiWelcomeMsg</span><span class="ot"> ::</span> <span class="dt">String</span>
    <span class="dt">GHCiWelcomeMsg</span> <span class="fu">=</span> <span class="st">&quot;GHCi, version &quot;</span> <span class="fu">++</span> cProjectVersion <span class="fu">++</span>
                     <span class="st">&quot;: http://www.haskell.org/GHC/  :? for help&quot;</span></code></pre></div>
<p>Next, add your own flair to the banner:</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    <span class="dt">GHCiWelcomeMsg</span><span class="ot"> ::</span> <span class="dt">String</span>
    <span class="dt">GHCiWelcomeMsg</span> <span class="fu">=</span> <span class="st">&quot;Hello GHC!\n&quot;</span> <span class="fu">++</span> <span class="st">&quot;GHCi, version &quot;</span> <span class="fu">++</span> cProjectVersion <span class="fu">++</span>
                     <span class="st">&quot;: http://www.haskell.org/GHC/  :? for help&quot;</span></code></pre></div>
<p>The quickest way to recompile GHC after making changes like this is to run <code>make stage=2</code> from the GHC directory.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">cd</span> <span class="ot">$(</span><span class="kw">TOP</span><span class="ot">)</span>/ghc
    <span class="kw">make</span> 2</code></pre></div>
<p><code>make 2</code> is an alias for <code>make stage=2 FAST=YES</code>.</p>
<p>You can find more information on that process <a href="https://GHC.haskell.org/trac/GHC/wiki/Building/Using#DevelopinginaGHCbuildtree">here</a>.</p>
<p>Now run GHCi with your new flair:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    $ <span class="ot">$(</span><span class="kw">TOP</span><span class="ot">)</span><span class="kw">/inplace/bin/GHC-stage2</span> --interactive
    <span class="kw">Hello</span> GHC!
    <span class="kw">GHCi</span>, version 7.9.20140412: http://www.haskell.org/GHC/  :? for help
    <span class="kw">Loading</span> package GHC-prim ... linking ... done.
    <span class="kw">Loading</span> package integer-gmp ... linking ... done.
    <span class="kw">Loading</span> package base ... linking ... done.
    <span class="kw">Prelude&gt;</span> </code></pre></div>
<p>Happy Hacking!</p>
<hr />
<h5 id="httpen.wikipedia.orgwikiglasgow_haskell_compilerarchitecture"><a name="0"></a>[0] - <a href="http://en.wikipedia.org/wiki/Glasgow_Haskell_Compiler#Architecture" class="uri">http://en.wikipedia.org/wiki/Glasgow_Haskell_Compiler#Architecture</a></h5>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>Teasers in Hakyll</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-04-08-hakyll-teasers.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-04-08-hakyll-teasers.html</id>
    <published>2014-04-08T00:00:00Z</published>
    <updated>2014-04-08T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on April  8, 2014
    
        by Christopher Reichert
    
</div>

<div style="text-align:center" markdown="1">
<p><img src="/images/haskell_logo1.png" alt="Hakyll Lambda" style="height: 250px;"/></p>
</div>
<p>While building this blog, one of the primary issues I faced was figuring out how to implement post teasers. Most of the resources I found were using teasers in an rss or atom feed. The <a href="http://jaspervdj.be/hakyll/tutorials/using-teasers-in-hakyll.html">Hakyll tutorial</a> on teasers was helpful but I found I needed a little more handholding. Partially, because I misunderstood how template contexts work in Hakyll.</p>
<p>This post describes how to implement teasers in Hakyll on the default generated test site.</p>
<!--more-->
<h3 id="generate-test-site">Generate Test Site</h3>
<p>Say you generate a site <code>foo</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">hakyll-init</span> foo
    <span class="kw">cd</span> foo</code></pre></div>
<p>Run the site to view the existing list of posts.</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">ghc</span> --make -threaded site.hs
    <span class="kw">./site</span> preview</code></pre></div>
<p>Point your browser to <a href="http://localhost:8000" class="uri">http://localhost:8000</a>. A list of posts should be displaying on the homepage. All is good.</p>
<p>The goal is to show a preview of each post in the post-list.html template. This would be visible on the homepage. Luckily, Hakyll has builtin functions to support extracting this information.</p>
<h3 id="modifying-the-html-templates">Modifying the HTML Templates</h3>
<p>What would this look like from an html perspective?</p>
<p>First, we need to add a template variable for the teaser to our post-list.html template. This way, a preview is shown every time we use the post-list template.</p>
<p>This is the html template for a list of posts before we add the teaser:</p>
<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">    <span class="kw">&lt;ul&gt;</span>
        $for(posts)$
            <span class="kw">&lt;li&gt;</span>
                <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">&quot;$url$&quot;</span><span class="kw">&gt;</span>$title$<span class="kw">&lt;/a&gt;</span> - $date$
            <span class="kw">&lt;/li&gt;</span>
        $endfor$
    <span class="kw">&lt;/ul&gt;</span></code></pre></div>
<p>Now we will add a variable <code>$teaser$</code>:</p>
<div class="sourceCode"><pre class="sourceCode html"><code class="sourceCode html">    <span class="kw">&lt;ul&gt;</span>
        $for(posts)$
            <span class="kw">&lt;li&gt;</span>
                <span class="kw">&lt;a</span><span class="ot"> href=</span><span class="st">&quot;$url$&quot;</span><span class="kw">&gt;</span>$title$<span class="kw">&lt;/a&gt;</span> - $date$
                <span class="kw">&lt;p&gt;</span>
                $if(teaser)$
                    $teaser$
                $else$
                    $body$
                $endif$
                <span class="kw">&lt;/p&gt;</span>
            <span class="kw">&lt;/li&gt;</span>
        $endfor$
    <span class="kw">&lt;/ul&gt;</span></code></pre></div>
<p>If you do not plan on defining <code>&lt;!--more--&gt;</code> in each blog post then you should conditionally check for <span class="math inline"><em>t</em><em>e</em><em>a</em><em>s</em><em>e</em><em>r</em></span>:</p>
<pre><code>$if(teaser)$
    $teaser$
$else$
    $body$
$endif$</code></pre>
<p>Hakyll’s <code>teaserField</code> function (used to build teasers) will fail if the <code>&lt;!--more--&gt;</code> tag is not defined in the post. The <code>&lt;!--more--&gt;</code> tag tells Hakyll where the teaser stops.</p>
<h3 id="the-haskell-code">The Haskell Code</h3>
<p>Now that we have added the <code>$teaser$</code> value to our template we need to make sure we add the Haskell code to add the teasers to our context. Open up <code>site.hs</code> in your favorite editor:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">vim</span> site.hs</code></pre></div>
<p>First, we must save a snapshot when generating posts. This must be done before any templates are applied:</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    match <span class="st">&quot;posts/*&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
        route <span class="fu">$</span> setExtension <span class="st">&quot;html&quot;</span>
        compile <span class="fu">$</span> pandocCompiler
            <span class="fu">&gt;&gt;=</span> saveSnapshot <span class="st">&quot;content&quot;</span>
            <span class="fu">&gt;&gt;=</span> loadAndApplyTemplate <span class="st">&quot;templates/post.html&quot;</span>    postCtx
            <span class="fu">&gt;&gt;=</span> loadAndApplyTemplate <span class="st">&quot;templates/default.html&quot;</span> postCtx</code></pre></div>
<p>We save the snapshot <code>content</code> during the compilation phase. Now, we must get the teaser from the same snapshot when loading a list of posts. Posts are added to a context using the <code>listField</code> function. Here is an example of a route that loads a list of posts:</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    match <span class="st">&quot;index.html&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
        route idRoute
        compile <span class="fu">$</span> <span class="kw">do</span>
            posts <span class="ot">&lt;-</span> recentFirst <span class="fu">=&lt;&lt;</span> loadAll <span class="st">&quot;posts/*&quot;</span> 
            <span class="kw">let</span> indexCtx <span class="fu">=</span>
                    listField <span class="st">&quot;posts&quot;</span> postCtx (return posts) <span class="ot">`mappend`</span>
                    constField <span class="st">&quot;title&quot;</span> <span class="st">&quot;Home&quot;</span>                <span class="ot">`mappend`</span>
                    defaultContext
        <span class="fu">...</span></code></pre></div>
<p>We must use the <code>teaserField</code> function to add the teasers to our context for each post. Thus, we want to add the teaser to the post context for each post.</p>
<p>We define a convencience function to create a context for teasers based off the post’s context <code>postCtx</code>:</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    teaserCtx <span class="fu">=</span> teaserField <span class="st">&quot;teaser&quot;</span> <span class="st">&quot;content&quot;</span> <span class="ot">`mappend`</span> postCtx</code></pre></div>
<p>Now we can use this context in each post. We must also load the snapshots during the compile phase using <code>loadAllSnapshots</code>:</p>
<div class="sourceCode"><pre class="sourceCode haskell"><code class="sourceCode haskell">    match <span class="st">&quot;index.html&quot;</span> <span class="fu">$</span> <span class="kw">do</span>
        route idRoute
        compile <span class="fu">$</span> <span class="kw">do</span>
            posts <span class="ot">&lt;-</span> recentFirst <span class="fu">=&lt;&lt;</span> loadAllSnapshots <span class="st">&quot;posts/*&quot;</span> <span class="st">&quot;content&quot;</span>
            <span class="kw">let</span> indexCtx <span class="fu">=</span>
                    listField <span class="st">&quot;posts&quot;</span> teaserCtx (return posts) <span class="ot">`mappend`</span>
                    constField <span class="st">&quot;title&quot;</span> <span class="st">&quot;Home&quot;</span>                <span class="ot">`mappend`</span>
                    defaultContext
        <span class="fu">...</span></code></pre></div>
<p>You should do this for every page that uses the post-list template. In our case this also include the archive page.</p>
<p>Now you should be able to see teasers on your posts: <a href="http://localhost:8000" class="uri">http://localhost:8000</a></p>
<p>Happy Hacking.</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>The WP-Evernote Plugin</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-04-06-wp-evernote.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-04-06-wp-evernote.html</id>
    <published>2014-04-06T00:00:00Z</published>
    <updated>2014-04-06T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on April  6, 2014
    
        by Christopher Reichert
    
</div>

<div style="text-align:center" markdown="1">
<p><img src="/images/wp-evernote.png" alt="WP-Evernote logo" style="height:300px"/></p>
</div>
<hr>
<h6 id="tldr-we-wrote-an-evernote-plugin-for-wordpress-wp-evernote">TL;DR We wrote an Evernote Plugin for Wordpress: <a href="https://github.com/creichert/wpevernote">WP-Evernote</a></h6>
<p>Recently, my brother and I were asked to add support for publishing blog posts on a <a href="http://wordpress.org">Wordpress</a> site from <a href="http://evernote.com">Evernote</a>. While taking a look at some existing plugins that might support this workflow, I came across <a href="http://wordpress.org/plugins/everpress/">Everpress</a>. Unfortunatly, Everpress is based off using an RSS feed which is no longer supported by Evernote (and hasn’t been for some time).</p>
<!--more-->
<p>We took this awesome opportunity to develop a custom Wordpress plugin using the Evernote api. WP-Evernote can publish notes in an Evernote public notebook to wordpress posts and also keep them up-to-date. WP-Evernote is still under development and can be found on my <a href="https://github.com/creichert/wpevernote">Github</a>. WP-Evernote is written in PHP and uses the <a href="https://github.com/evernote/evernote-sdk-php">Evernote PHP SDK</a>.</p>
<p>This post describes how to install and test the current development version of WP-Evernote.</p>
<div class="warning">
<p>If you do not know how to use Git I will be more than happy to create a zip archive for you. I will be providing zip archive release files on Github when the plugin is more user friendly.</p>
</div>
<p></br></p>
<h3 id="install">Install</h3>
<p>Navigate to the Wordpress plugin directory:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">cd</span> wp-content/plugins/
    <span class="kw">git</span> clone git@github.com:creichert/wpeverpress</code></pre></div>
<p>There should now be a copy of the wpeverpress source in the Wordpress plugin directory. There are a few files of interest in the plugin:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    $ <span class="kw">tree</span> wpevernote
        <span class="kw">wpevernote</span>
        ├── <span class="kw">evernote-sdk-php</span>
        ├── <span class="kw">readme.txt</span>
        ├── <span class="kw">wpevernote-panel.html</span>
        └── <span class="kw">wpevernote.php</span></code></pre></div>
<p><code>wpevernote.php</code> contains the php code that drives the plugin. <code>wpevernote-panel.html</code> contains the WP-Evernote settings panel. <code>evernote-sdk-php</code> contains the Evernote api client library. The <code>readme.txt</code> file contains documentation about wpevernote.</p>
<h3 id="configure">Configure</h3>
<p>In Wordpress, Go to the <code>Settings -&gt; WP Evernote</code> settings panel.</p>
<p>The first thing you must do is setup api keys so you can fetch data from Evernote. To get API keys go to the <a href="http://dev.evernote.com/doc/">Evernote API</a> website. Click on the “Get An API Key” button and enter the form details:</p>
<ul>
<li>Evernote Username</li>
<li>Developer Name</li>
<li>Developer Email</li>
<li>Organization</li>
<li>App Name</li>
<li>Describe app</li>
</ul>
<p>You will be presented with your api credentials immediately. These keys will only work on the Evernote sandbox website and are not enabled for the production website. There is a small process involved in getting these api keys authorized to use the production servers.</p>
<p>Go back to the WP-Evernote settings panel and enter in the consumer key and consumer secret in the Settings form. Then hit “Save Settings”.</p>
<p>You should be redirected to an Evernote OAuth authentication website. You must Authorize the plugin here in order for WP-Evernote access to the Evernote data.</p>
<p>Upon successful authentication, you will be directed back to the WP-Evernote settings panel. Now you can add your first notebook.</p>
<div class="warning">
<p>The Evernote API uses OAuth for authentication. You must be on a valid url capable of dns lookup. This is a major limitation of testing sandbox data. You can get access to your sandbox auth token directly to avert this issue.</p>
</div>
<p><br/></p>
<h3 id="add-a-notebook">Add A Notebook</h3>
<p>Assuming you authenticated correctly, it’s time to add your first notebook. In order to add a notebook, the notebook must be public.</p>
<p>Place the full url of your public notebook in the <code>Publice notebook url</code> form area then click the <code>Add Notebook</code> button. If your notebook was added correctly you should now see it in the <code>Current Notebooks</code> area.</p>
<p>A post will be created for each note in your notebooks. The posts are uniquely identified by the Evenote guid for notes. Therefore, if you were to change the title of the note in evernote and update your notebooks, they will properly import and update the correct posts without creating duplicates.</p>
<h3 id="updating-your-notebooks">Updating your notebooks</h3>
<p>Support for scheduled notebook updates is still under development.</p>
<p>You can manually update your notebooks using the <code>Update Notebooks</code> button on the WP-Evernote settings panel.</p>
<p>As mentioned before, notes are synced based on their Evernote guid. Any changes you make in Evernote will sync to the correct post. This helps to avoid duplicate posts.</p>
<h3 id="conclusions">Conclusions</h3>
<p>Despite some of the complications using api keys, we think this plugin will be an extremely useful tool for people who use Evernote and Wordpress. We are looking for testers so we can improve the user experience and add features. If you would like to help test or even contribute to the code, feel free to <a href="/#contact">Contact</a> me.</p>
<p>Cheers!</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>
<entry>
    <title>The Reichert Brothers Blog</title>
    <link href="http://reichertbrothers.com/blog/posts/2014-02-07-reichert-brothers-blog.html" />
    <id>http://reichertbrothers.com/blog/posts/2014-02-07-reichert-brothers-blog.html</id>
    <published>2014-02-07T00:00:00Z</published>
    <updated>2014-02-07T00:00:00Z</updated>
    <summary type="html"><![CDATA[<div class="info">
    Posted on February  7, 2014
    
        by Christopher Reichert
    
</div>

<h4 id="welcome-to-the-reichert-brothers-blog">Welcome to the Reichert Brothers Blog!</h4>
<div style="text-align:center" markdown="1">
<p><img src="/images/rblogo.png" alt="Reichert Brothers" style="height:300px"/></p>
</div>
<p>We finally built it! Our hope is to give back to the software development community that we have learned so much from. We encounter a lot of peculiar problems throughout our hacking journey and we want to make this a forum to discussion related issues.</p>
<!--more-->
<h5 id="what-is-the-blog-built-on">What is the blog built on?</h5>
<p>This blog (and our entire site) is built on <a href="http://jaspervdj.be/hakyll/">Hakyll</a>, a static site generator written in <a href="http://haskell.org">Haskell</a>.</p>
<blockquote>
<p>Static sites are fast, secure, easy to deploy, and manageable using version control. — <cite>Hakyll documentation</cite></p>
</blockquote>
<p>If you don’t know any Haskell don’t be intimidated! The amount of Haskell code it takes to get up and running is quite minimal. The rest of this post will be a short tutorial on getting started with Hakyll. This is also covered in <a href="http://jaspervdj.be/hakyll/tutorials/01-installation.html">The Hakyll Documentation</a>.</p>
<h5 id="how-can-i-build-a-hakyll-site">How can I build a Hakyll site?</h5>
<p>Hakyll is simple to install if you are familiar with <code>cabal</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">cabal</span> install hakyll</code></pre></div>
<p>Use the <code>hakyll-init</code> executable to generate an example site:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">hakyll-init</span> foo</code></pre></div>
<p>Then compile your site using <code>ghc</code>:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">cd</span> foo
    <span class="kw">ghc</span> --make -threaded site.hs</code></pre></div>
<p>You can now run the hakyll preview server to test the site:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">./site</span> preview</code></pre></div>
<p>Your site should be visible at <a href="http://localhost:8000" class="uri">http://localhost:8000</a>.</p>
<p>Not only does Hakyll provide the preview server, it also integrates extremely easily with <a href="http://nginx.org">NGinx</a>, <a href="http://apache.org">Apache</a>, and other web servers. Use the build command to compile the site:</p>
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash">    <span class="kw">./site.hs</span> build</code></pre></div>
<p>This command creates a directory <code>_site</code> which contains the compiled site. NGinx, for example, can point directly to this using the root directive:</p>
<pre><code>root /path/to/foo/_site;</code></pre>
<p>Happy Hacking!</p>

<hr>
<!-- the comment box -->
<div class="well">
    <div id="disqus_thread"></div>
      <script type="text/javascript">
          /* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
          var disqus_shortname = 'reichertbrothers'; // required: replace example with your forum shortname

          /* * * DON'T EDIT BELOW THIS LINE * * */
          (function() {
              var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
              dsq.src = '//' + disqus_shortname + '.disqus.com/embed.js';
              (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
          })();
      </script>
      <noscript>Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
      <a href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a>
</div>
]]></summary>
</entry>

</feed>
